error in editing byte[] from images
I'm trying to do image processing on wp7, and now i finished convertImagetoBytes and convertByteToBitmapImage.
I suppose I can change the values in the byte array to do some image processing work, but it turns out to be a black image in the picturebox. (Now I just wanna process .jpg images)
convertImagetoBytes
byte[] data = null;
using (MemoryStream stream = new MemoryStream())
{
WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
wBitmap.SaveJpeg(stream, wBitmap.PixelWidth, wBitmap.PixelHeight, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
data = stream.GetBuffer();
}
convertBytestoImage
Memo开发者_如何学JAVAryStream stream = new MemoryStream(bytes);
stream.Position = 0;
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);
return bi;
now if i change the values in the byte array,just like this(grayscale)
for (int i = 0; i < bytesCount; i+=4)
{
colorTemp = data[i+2];
data[i+1 ] =data[i+2]= data[i + 3] = (byte)colorTemp;
}
the image turns out to be black.
You've saved it as a JPEG - but you appear to be trying to change it as if it were raw data. You can't just mess around with the data of a JPEG file to fake greyscale.
By the way, you should use stream.ToArray
instead of stream.GetBuffer()
as the latter will usually be larger than the real data.
You should also look into using René Schulte's WriteableBitmapEx library.
And consider reading this article about a Windows Phone Picture Effects Application
精彩评论