开发者

where did PixelFormats and WriteableBitmap.Lock go in Silverlight3?

A few months ago I built some online samples like this one from Jeff Prosise that use the WriteableBitmap class in Silverlight.

Revisiting them today with the latest Silverlight3 installer (3.0.40624.0), the API seems to have changed.

I figured out some of the changes. For example, the WriteableBitmap array accessor has disappeared, but I found it in the new Pixels pro开发者_运维技巧perty, so instead of writing:

 bmp[x]

I can write

bmp.Pixels[x]

Are there similar simple replacements for these calls, or has the use pattern itself changed?

bmp = new WriteableBitmap(width, height, PixelFormats.Bgr32);
bmp.Lock();
bmp.Unlock();

Can anybody point me to a working example using the updated API?


Another important detail about switching to the new WriteableBitmap is given in this answer ... because the pixel format is now always pbgra32, you must set an alpha value for each pixel, otherwise you just get an all-white picture. In other words, code that formerly generated pixel values like this:

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

should be changed to read:

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


What happens if you don't use Lock and Unlock and just use the WritabelBitmap(int, int) constructor? Do things break?

It would seem that between SL3 Beta and the release this API has changed. See Breaking Changes Document Errata (Silverlight 3)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜