简体   繁体   中英

Bitmap in silverlight?

I need to send using WCF some image that the user dynamically load ( using browse ). The WCF service can have Bitmap object ( byte[] ).

The image format that i hold is ImageBrush. I don't see that silverlight have Bitmap object => so how can i convert the ImageBrush that i hold to the right object that the WCF service expect me to send ?

How can i solve this issue ?

The ImageBrush isn't an image itself but an object used to paint the image. The image itself should be held in imageBrush.ImageSource. This ImageSource can be of various types that subclass it, the most common being BitmapSource. BitmapSource has a method CopyPixels which can be used to extract the Pixels from the source which can then be passed up to your WCF service.

var stride = bitmapSource.PixelWidth + (bitmapSource.PixelWidth) % 4;
var byteArray = new byte[bitmapSource.PixelHeight * stride];
bitmapSource.CopyPixels(byteArray, stride, 0);

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