在Android中,位图外观看起来不太好,抖动不起作用

时间:2011-05-13 11:26:07

标签: android bitmap dithering

我想在我的应用中使用coverflow视图。为了获得反射图像部分,我使用了以下代码 - http://www.androidsnippets.com/create-image-with-reflection

我见过很多关于抖动和tileMode的论坛/讨论,我已经尝试了所有讨论但没有任何作用。

仅供参考 - 我在动态创建位图而不使用布局中的任何位图。我已附上图片以显示它有多糟糕:

Reflection image appearance is not looking good

我在下面列出了我试图解决此问题的方法。

   1. getWindow().setFlags(WindowManager.LayoutParams.FLAG_DITHER, WindowManager.LayoutParams.FLAG_DITHER);

   2. getWindow().setFormat(PixelFormat.RGBA_8888);


   3. BitmapDrawable baseImageDawable = new BitmapDrawable(getResources().openRawResource(imageId));
      baseImageDawable.setDither(true);
      baseImageDawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);

      Bitmap originalImage = baseImageDawable.getBitmap();
      int width = originalImage.getWidth();
      int height = originalImage.getHeight();

      Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, 0, width, height, matrix, true);   

但是反射图像仍然很难看。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:4)

嗯。我“想”你的问题是你的位图没有被创建为ARGB_8888(尽管你的setFormat调用)。我会“建议”,而不是使用openRawResource创建Bitmap drawable,使用BitmapFactory并确保指定Bitmap.Config.ARGB_8888。然后从位图制作您的drawable。只是一个想法 - 难以猜测这个距离,而不能与日食同步。您可能会发现这篇文章很有趣:http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

编辑:所以,问题显然是在调用createBitmap用于分配reflectionImage。故事的道德(恕我直言):永远不要使用不允许您显式指定Bitmap.Config的createBitmap方法。否则,正如阿甘正传所言,你永远不会知道你会得到什么。

答案 1 :(得分:1)

我找到了应该在哪里设置配置的位置。在创建反射位图时,将配置设置为ARGB_8888。它现在正在工作。