2012-01-31 125 views
1

我在做一个绘图应用程序。我已将颜色填充图像保存为集合中的bitmapImage。我再次打开保存的图像进行绘制。如果我填充图像的颜色,颜色填充不清楚。我已经使用ExtensionJpg保存图像。绘图应用程序 - 填充颜色在Windows Phone7中保存为BitmapImage

  WriteableBitmap pBitmap; 
      pBitmap = new WriteableBitmap(imgDraw, null); // imgDraw is jpg image bitmapImage binded to source. 

      BitmapImage img1 = new BitmapImage(); 
      MemoryStream ms = new MemoryStream(); 
      pBitmap.SaveJpeg(ms, (int)pBitmap.PixelWidth, (int)pBitmap.PixelHeight, 0, 100);     
      img1.SetSource(ms); 

在这种情况下,我再次将这个位图Image绑定到imgDraw Source。但看到图像非常清晰。 当我填充颜色imgDraw没有正确应用。

谢谢

回答

2

当您将位图编码为Jpeg文件时,可能会丢失数据。这是诸如Jpeg之类的lossy compression algorithms设计的一部分。

更糟糕的是,使用有损压缩可能会引入(几乎看不见)伪像。因此,通过将图像保存为Jpeg,您可能会将像素添加到大而清晰的区域。这些像素会导致填充失败。

你有三个选择:

  1. 不要通过切换到例如使用有损算法PNG
  2. 更改压缩质量
  3. 将填充算法更改为对几乎相同颜色的像素更具有容忍性。

我注意到,您将质量设置为100,但this question makes me doubt the quality of the jpeg implementation您可能正在使用的方法。你可以切换到PNG,看看是否有帮助。

+0

感谢您的回复。这对我很有帮助 – user1120998 2012-01-31 06:54:23

+0

没问题,它解决了这个问题吗? – 2012-01-31 06:59:43

+0

谢谢,我已将jpeg转换为png。它的工作。 – user1120998 2012-01-31 09:13:51