Ste*_*ald 3 windows-phone-7 windows-phone-8
如何在Windows Phone 8中将普通图像转换为灰度图像.在WritableBitmapEx中是否有任何灰度转换的规定.
try this extension method...
public static WriteableBitmap ToGrayScale(this WriteableBitmap bitmapImage)
{
for (var y = 0; y < bitmapImage.PixelHeight; y++)
{
for (var x = 0; x < bitmapImage.PixelWidth; x++)
{
var pixelLocation = bitmapImage.PixelWidth * y + x;
var pixel = bitmapImage.Pixels[pixelLocation];
var pixelbytes = BitConverter.GetBytes(pixel);
var bwPixel = (byte)(.299 * pixelbytes[2] + .587 * pixelbytes[1] + .114 * pixelbytes[0]);
pixelbytes[0] = bwPixel;
pixelbytes[1] = bwPixel;
pixelbytes[2] = bwPixel;
bitmapImage.Pixels[pixelLocation] = BitConverter.ToInt32(pixelbytes, 0);
}
}
return bitmapImage;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1186 次 |
| 最近记录: |