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);
精彩评论