几个月前,我构建了一些在线示例,例如 this one from Jeff Prosise在 Silverlight 中使用 WriteableBitmap 类。
今天使用最新的 Silverlight3 安装程序 (3.0.40624.0) 重新访问它们,API 似乎已更改。
我想出了一些变化。例如,WriteableBitmap 数组访问器已经消失,但我在新的 Pixels 属性中找到了它,所以我没有写:
bmp[x]
我会写
bmp.Pixels[x]
这些调用是否有类似的简单替换,或者使用模式本身是否发生了变化?
bmp = new WriteableBitmap(width, height, PixelFormats.Bgr32);
bmp.Lock();
bmp.Unlock();
谁能给我指出一个使用更新后的 API 的工作示例?
最佳答案
关于切换到新的 WriteableBitmap 的另一个重要细节在 this answer 中给出。 ...因为像素格式现在总是 pbgra32,你必须为每个像素设置一个 alpha 值,否则你只会得到一张全白的图片。换句话说,以前生成像素值的代码如下:
byte[] components = new byte[4];
components[0] = (byte)(blue % 256); // blue
components[1] = (byte)(grn % 256); // green
components[2] = (byte)(red % 256); // red
components[3] = 0; // unused
应该改为:
byte[] components = new byte[4];
components[0] = (byte)(blue % 256); // blue
components[1] = (byte)(grn % 256); // green
components[2] = (byte)(red % 256); // red
components[3] = 255; // alpha
关于silverlight - PixelFormats 和 WriteableBitmap.Lock 在 Silverlight3 中去了哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827355/