uwp 图像处理例子
async void test() { Color replaceBlack = Color.FromArgb(224,233,55,6); Color replaceWhite = Color.FromArgb(224, 233, 222, 222); // BitmapImage bmpimg = new BitmapImage(); WriteableBitmap source = this.imageSource1.Source as WriteableBitmap; //need make sure the .imageSource1.Source is WriteableBitmap byte[] byteArray = null; using (Stream stream = source.PixelBuffer.AsStream()) { long streamLength = stream.Length; byteArray = new byte[streamLength]; await stream.ReadAsync(byteArray, 0, byteArray.Length); if (streamLength > 0) { for (int i = 0; i < streamLength; i += 4) { if (byteArray[i + 3] != 0) { int b = Convert.ToInt32(byteArray[i]); int g = Convert.ToInt32(byteArray[i + 1]); int r = Convert.ToInt32(byteArray[i + 2]); int rB = ((((b * replaceBlack.B) / 255) + (((255 - b) * replaceWhite.B) / 255)) / 2); int rG = ((((g * replaceBlack.G) / 255) + (((255 - g) * replaceWhite.G) / 255)) / 2); int rR = ((((r * replaceBlack.R) / 255) + (((255 - r) * replaceWhite.R) / 255)) / 2); byte blue = Convert.ToByte(rB); byte green = Convert.ToByte(rG); byte red = Convert.ToByte(rR); byteArray[i] = blue; // Blue byteArray[i + 1] = green; // Green byteArray[i + 2] = red; // Red } } } } if (byteArray != null) { int lw, lh; lw = source.PixelWidth; lh = source.PixelHeight; WriteableBitmap wbbitmap = new WriteableBitmap(source.PixelWidth, source.PixelHeight); Stream s = wbbitmap.PixelBuffer.AsStream(); s.Seek(0, SeekOrigin.Begin); s.Write(byteArray, 0, lw * lh * 3); s.Flush(); this.imageTarget2.Source = null; this.imageTarget2.Source = wbbitmap; } }
fffffffffffffffff
test red font.