本文介绍了如何在Silverlight 4中在服务器端保存Writeable位图或图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
bitmap.Pixels [matrixPos]在运行时生成"WriteableBitmap has protected content. Pixel access is not allowed.
"错误.我没有得到字节数组.请帮助.
bitmap.Pixels[matrixPos] generates a "WriteableBitmap has protected content. Pixel access is not allowed.
" error at runtime. I am not getting byte array. Help please.
WriteableBitmap bitmap;
//screenGrab is the Image
screenGrab.Source = null;
var aboutTheShowPage = ((App)Application.Current).RootVisual as Grid;
var aboutTheShowMainPage = aboutTheShowPage.Children[0] as MainPage;
var wShowListSubMenuExaboutTheShowPage = aboutTheShowMainPage.viewbox.Child as WShowListSubMenuEx;
this.bitmap = new WriteableBitmap((int)wShowListSubMenuExaboutTheShowPage.ActualWidth, (int)wShowListSubMenuExaboutTheShowPage.ActualHeight);
bitmap.Render(wShowListSubMenuExaboutTheShowPage, this.transform);
bitmap.Invalidate();
// set the source of our transition image to the WriteableBitmap
this.screenGrab.Source = bitmap;
long matrixSize = bitmap.PixelWidth * bitmap.PixelHeight;
long byteSize = matrixSize * 4 + 4;
byte[] retVal = new byte[byteSize];
long bufferPos = 0;
retVal[bufferPos++] = (byte)((bitmap.PixelWidth / 256) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.PixelWidth % 256) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.PixelHeight / 256) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.PixelHeight % 256) & 0xff);
for (int matrixPos = 0; matrixPos < matrixSize; matrixPos++)
{
retVal[bufferPos++] = (byte)((bitmap.Pixels[matrixPos] >> 24) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.Pixels[matrixPos] >> 16) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.Pixels[matrixPos] >> 8) & 0xff);
retVal[bufferPos++] = (byte)((bitmap.Pixels[matrixPos]) & 0xff);
}
推荐答案
这篇关于如何在Silverlight 4中在服务器端保存Writeable位图或图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!