简体   繁体   中英

Get IntPtr value from BitmapImage or stream in UWP

I'm working with image processing in WinForm and it work very well when I have Bitmap and BitmapData, I can easily get IntPtr from it. But in UWP, I have no way to get IntPtr from them. So do we have any way to do that?

UPDATE: If we cannot get IntPtr value, can we get the pointer address for that image? Something like this in WinForm:

byte* src = (byte*) BitmapData.Scan0.ToPointer( );

You could get pxiel data from file stream via BitmapDecoder and PixelDataProvider:

Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/StoreLogo.png")).OpenReadAsync();
        Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
        Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
        byte[] buffer = pixelData.DetachPixelData();

Then you could get Intptr from byte array via unsafe code

unsafe
        {
            fixed (byte* p = buffer)
            {
                IntPtr ptr = (IntPtr)p;
                // do you stuff here
            }
        }

If compile unsafe code, you need to enable the Allow Unsafe Code option in project's build property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM