当前位置: 首页>>代码示例>>C#>>正文


C# GCHandle.AddrOfPinnedObject方法代码示例

本文整理汇总了C#中GCHandle.AddrOfPinnedObject方法的典型用法代码示例。如果您正苦于以下问题:C# GCHandle.AddrOfPinnedObject方法的具体用法?C# GCHandle.AddrOfPinnedObject怎么用?C# GCHandle.AddrOfPinnedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GCHandle的用法示例。


在下文中一共展示了GCHandle.AddrOfPinnedObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

    void Update()
    {
        if (state == 0) {
            AndroidJavaClass UnityOpenCVLoaderJava = new AndroidJavaClass(UNITY_OPENCV_LOADER);
            var b = UnityOpenCVLoaderJava.CallStatic<Boolean>("isSuccess");
            if (b) {
                state = 1;
            }
        } else if (state == 1) {
            if (cameraInstance == IntPtr.Zero) cameraInstance = CreateCameraInstance ();

            if (Open (cameraInstance, 0, width, height)) {
                texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
                pixels = texture.GetPixels32 ();
                pixelsHandle = GCHandle.Alloc (pixels, GCHandleType.Pinned);
                pixelsPtr = pixelsHandle.AddrOfPinnedObject ();
                GetComponent<Renderer>().material.mainTexture = texture;
                state = 2;
            } else {
                state = -1;
            }
        } else if (state == 2) {
            getCameraTexture (cameraInstance, pixelsPtr, width, height);
            texture.SetPixels32 (pixels);
            texture.Apply ();
        }
    }
开发者ID:rinsyan0518,项目名称:UnityOpenCV,代码行数:27,代码来源:OpenCVCamera.cs

示例2: DoLoadBank

	private static AKRESULT DoLoadBank(string in_bankPath)
	{
		ms_www = new WWW(in_bankPath);
		while( ! ms_www.isDone )
		{
#if ! UNITY_METRO
			System.Threading.Thread.Sleep(WaitMs);
#endif // #if ! UNITY_METRO
		}

		uint in_uInMemoryBankSize = 0;
		try
		{
			ms_pinnedArray = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
			ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
			in_uInMemoryBankSize = (uint)ms_www.bytes.Length;	
		}
		catch
		{
			return AKRESULT.AK_Fail;
		}
		
		AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);
		
		return result;
	}
开发者ID:Arpit0492,项目名称:Unity,代码行数:26,代码来源:AkInMemBankLoader.cs

示例3: Update

    // Update is called once per frame
    void Update()
    {
        // off-screen rendering
        var camtex = RenderTexture.GetTemporary (camWidth, camHeight, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
        myCamera.targetTexture = camtex;
        myCamera.Render ();
        RenderTexture.active = camtex;

        tex.ReadPixels (new Rect (0, 0, camtex.width, camtex.height), 0, 0);
        tex.Apply ();

        // Convert texture to ptr
        texturePixels_       = tex.GetPixels32();
        texturePixelsHandle_ = GCHandle.Alloc(texturePixels_, GCHandleType.Pinned);
        texturePixelsPtr_    = texturePixelsHandle_.AddrOfPinnedObject();

        // Show a window
        fullWindow (windowName, displayNum, texturePixelsPtr_, camWidth, camHeight);

        texturePixelsHandle_.Free();

        RenderTexture.active = null;
        RenderTexture.ReleaseTemporary (camtex);
        myCamera.targetTexture = null;
    }
开发者ID:kurepasu0731,项目名称:ProjectionMapping,代码行数:26,代码来源:multiWindow.cs

示例4: CreateBuffer

	private void CreateBuffer(int width, int height)
	{
		// Free buffer if it's too small
		if (_frameHandle.IsAllocated && _frameData != null)
		{
			if (_frameData.Length < _frameWidth * _frameHeight)
			{
				FreeBuffer();
			}
		}
		
		if (_frameData == null)
		{
			_frameWidth = width;
			_frameHeight = height;
			_frameData = new Color32[_frameWidth * _frameHeight];
			_frameHandle = GCHandle.Alloc(_frameData, GCHandleType.Pinned);
			_framePointer = _frameHandle.AddrOfPinnedObject();
			
#if TEXTURETEST
			_testTexture = new Texture2D(_frameWidth ,_frameHeight, TextureFormat.ARGB32, false, false);
			_testTexture.Apply(false, false);
#endif
		}
	}
开发者ID:vovo5558,项目名称:NewScopePlus,代码行数:25,代码来源:AVProLiveCameraGrabber.cs

示例5: Matrix

    public Matrix(int size)
    {
        if (!_validSizes.Contains(size)) throw new ArgumentOutOfRangeException("size");
        _size = size;
        _data = new int[size * size];

        _dataPtrHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
        _dataPtr = (int*)_dataPtrHandle.AddrOfPinnedObject().ToPointer();
    }
开发者ID:Farouq,项目名称:semclone,代码行数:9,代码来源:Matrix.cs

示例6: Start

	// Use this for initialization
	void Start () {
        camera_ = getCamera(device);
        setCameraProp(camera_, width, height, fps);
        texture_ = new Texture2D(width, height, TextureFormat.ARGB32, false);
        pixels_ = texture_.GetPixels32();
        pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
        pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
        GetComponent<Renderer>().material.mainTexture = texture_;
    }
开发者ID:kurepasu0731,项目名称:ProjectingLight,代码行数:10,代码来源:WebCamManager_native.cs

示例7: UpdateView

		/// <summary>
		/// Update the view. This method triggers the view to be rendered to the
		/// underlaying texture.
		/// </summary>
		/// <returns>true if the view was actually updated</returns>
		public bool UpdateView()
		{
			if (View != null)
			{
				m_DataPin = GCHandle.Alloc(m_Data,
					System.Runtime.InteropServices.GCHandleType.Pinned);

				return View.GetAsBitmap(m_DataPin.AddrOfPinnedObject(),
					Width * Height * 4);
			}
			return false;
		}
开发者ID:Scub3d,项目名称:Aerohacks,代码行数:17,代码来源:MobileSurfaceView.cs

示例8: Start

	void Start() 
	{
		camera_ = get_camera();
		if (camera_ == IntPtr.Zero) {
			Debug.LogError("camera cannot be opened.");
			return;
		}

		texture_ = new Texture2D(640, 480, TextureFormat.RGBA32, false);
		pixels_ = texture_.GetPixels32();
		handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
		ptr_ = handle_.AddrOfPinnedObject();
		GetComponent<Renderer>().material.mainTexture = texture_;
	}
开发者ID:AndroidHMD,项目名称:unity-android-aruco-sample,代码行数:14,代码来源:NativeCamera.cs

示例9: LoadFile

    IEnumerator LoadFile()
    {
        ms_www = new WWW(m_bankPath);

        yield return ms_www;

        uint in_uInMemoryBankSize = 0;

        // Allocate an aligned buffer
        try
        {
            ms_pinnedArray = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
            ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
            in_uInMemoryBankSize = (uint)ms_www.bytes.Length;

            // Array inside the WWW object is not aligned. Allocate a new array for which we can guarantee the alignment.
            if( (ms_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0 )
            {
                byte[] alignedBytes = new byte[ms_www.bytes.Length + AK_BANK_PLATFORM_DATA_ALIGNMENT];
                GCHandle new_pinnedArray = GCHandle.Alloc(alignedBytes, GCHandleType.Pinned);
                IntPtr new_pInMemoryBankPtr = new_pinnedArray.AddrOfPinnedObject();
                int alignedOffset = 0;

                // New array is not aligned, so we will need to use an offset inside it to align our data.
                if( (new_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0 )
                {
                    Int64 alignedPtr = (new_pInMemoryBankPtr.ToInt64() + AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) & ~AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK;
                    alignedOffset = (int)(alignedPtr - new_pInMemoryBankPtr.ToInt64());
                    new_pInMemoryBankPtr = new IntPtr(alignedPtr);
                }

                // Copy the bank's bytes in our new array, at the correct aligned offset.
                Array.Copy (ms_www.bytes, 0, alignedBytes, alignedOffset, ms_www.bytes.Length);

                ms_pInMemoryBankPtr = new_pInMemoryBankPtr;
                ms_pinnedArray.Free();
                ms_pinnedArray = new_pinnedArray;
            }
        }
        catch
        {
            yield break;
        }

        AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);
        if( result != AKRESULT.AK_Success )
        {
            Debug.LogError ("AkMemBankLoader: bank loading failed with result " + result.ToString ());
        }
    }
开发者ID:NunezG,项目名称:villeEmergente,代码行数:50,代码来源:AkMemBankLoader.cs

示例10: Start

	void Start()
	{
		// テクスチャを生成
		texture_ = new Texture2D(10, 10, TextureFormat.RGB24, false);
		// テクスチャの拡大方法をニアレストネイバーに変更
		texture_.filterMode = FilterMode.Point;
		// Color32 型の配列としてテクスチャの参照をもらう
		pixels_ = texture_.GetPixels32();
		// GC されないようにする
		pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
		// そのテクスチャのアドレスをもらう
		pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
		// スクリプトがアタッチされたオブジェクトのテクスチャをコレにする
		GetComponent<Renderer>().material.mainTexture = texture_;
		// ネイティブ側でテクスチャを生成
		create_check_texture(pixels_ptr_, texture_.width, texture_.height, 4);
		// セットして反映させる
		texture_.SetPixels32(pixels_);
		texture_.Apply(false, true);
		// GC 対象にする
		pixels_handle_.Free();
	}
开发者ID:AndroidHMD,项目名称:unity-android-aruco-sample,代码行数:22,代码来源:CheckTexture.cs

示例11: InitAwesomium

    public void InitAwesomium(int width, int height)
    {
        Debug.Log("init awsommium");
        this.width = width;
        this.height = height;
        m_texture = new Texture2D(width, height, TextureFormat.ARGB32, true);
        //Get Color[] (pixels) from texture
        m_pixels = m_texture.GetPixels(0);
        // Create window handle id - future usage
        m_TextureID = m_texture.GetInstanceID();
        Debug.Log("textID : " + m_TextureID);
        // assign m_texture to this GUITexture texture
        gameObject.renderer.material.mainTexture = m_texture;
        // Create GCHandle - Allocation of m_pixels in memory.
        m_pixelsHandler = GCHandle.Alloc(m_pixels, GCHandleType.Pinned);
        AwesomiumWrapper.Init();
        AwesomiumWrapper.CreateAwesomiumWebView(m_TextureID, m_pixelsHandler.AddrOfPinnedObject(), width, height, this.SetPixels, this.ApplyTexture);

        isAwesomiumInit = true;
        GetComponent<BrowserGUIEvents>().interactive = true;
        Debug.Log("done init awsommium");
    }
开发者ID:kelvinRosa,项目名称:UnityAwesomium,代码行数:22,代码来源:AwesomiumMeshRender.cs

示例12: Start

	void Start()
	{
		var path = GetFilePath(imagePath);
		int width, height;
		if (!get_image_size(path, out width, out height)) {
			Debug.LogFormat("{0} was not found", path);
			return;
		}

		texture_ = new Texture2D(width, height, TextureFormat.RGB24, false);
		texture_.filterMode = FilterMode.Point;
		pixels_ = texture_.GetPixels32();
		pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned);
		pixels_ptr_ = pixels_handle_.AddrOfPinnedObject();
		GetComponent<Renderer>().material.mainTexture = texture_;

		read_image(path, pixels_ptr_);

		texture_.SetPixels32(pixels_);
		texture_.Apply();
		pixels_handle_.Free();
	}
开发者ID:AndroidHMD,项目名称:unity-android-aruco-sample,代码行数:22,代码来源:ReadTexture.cs

示例13: LoadMovieFromResource

    public bool LoadMovieFromResource(bool autoPlay, string path)
    {
        bool result = false;

        UnloadMovie();

        _textAsset = Resources.Load(path, typeof(TextAsset)) as TextAsset;
        if (_textAsset != null)
        {
            if (_textAsset.bytes != null && _textAsset.bytes.Length > 0)
            {
                _bytesHandle = GCHandle.Alloc(_textAsset.bytes, GCHandleType.Pinned);
                result = LoadMovieFromMemory(autoPlay, path, _bytesHandle.AddrOfPinnedObject(), (uint)_textAsset.bytes.Length, FilterMode.Bilinear, TextureWrapMode.Clamp);
            }
        }

        if (!result)
        {
            Debug.LogError("[AVProWindowsMedia] Unable to load resource " + path);
        }

        return result;
    }
开发者ID:NikMifsud,项目名称:GreatSiege,代码行数:23,代码来源:AVProWindowsMediaMovieFromResource.cs

示例14: OnAudioFilterRead

    // Unity audio callback
    public void OnAudioFilterRead(float[] data, int channels)
    {
        if(dataPtr == IntPtr.Zero)
        {
            dataHandle = GCHandle.Alloc(data,GCHandleType.Pinned);
            dataPtr = dataHandle.AddrOfPinnedObject();
        }

        if (islibpdready) {
            LibPD.Process(numberOfTicks, dataPtr, dataPtr);
        }
    }
开发者ID:AVUIs,项目名称:wat,代码行数:13,代码来源:LibPdFilterRead.cs

示例15: AddrOfPinnedObject

 public static IntPtr AddrOfPinnedObject(GCHandle gh)
 {
     return gh.AddrOfPinnedObject();
 }
开发者ID:l1183479157,项目名称:coreclr,代码行数:4,代码来源:GCUtil.cs


注:本文中的GCHandle.AddrOfPinnedObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。