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

发布于 2024-11-07 08:39:13 字数 1142 浏览 9 评论 0原文

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

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

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

反射图像外观看起来不太好

我在下面列出了我的情况已经尝试解决这个问题。

   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);   

但反射图像仍然很丑陋。

我该如何解决这个问题?

I want to use coverflow view in my app. To get the reflection image part i have used the following code - http://www.androidsnippets.com/create-image-with-reflection

I have seen lot of forums/discussions about dithering and tileMode, I have tried all that discussed but nothing works for me.

FYI - I am creating a bitmap dynamically not using any bitmap in layouts. And I have attached the image to show how bad it is:

Reflection image appearance is not looking good

I have listed below what I have tried to solve this issue.

   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);   

But still the reflection image is very ugly.

How can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-11-14 08:39:13

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

编辑:所以,问题显然在于对 createBitmap 的调用被用来分配反射图像。这个故事的寓意(恕我直言):永远不要使用不允许您显式指定 Bitmap.Config 的 createBitmap 方法。否则,正如阿甘所说,你永远不知道你会得到什么。

Hmmm. I "think" your problem is that your bitmap is not being created as ARGB_8888 (despite your setFormat call). I would "suggest," instead of creating the Bitmap drawable using openRawResource, use BitmapFactory and make sure you specify Bitmap.Config.ARGB_8888. Then make your drawable from the bitmap. Just a thought--hard to guess at this distance without being able to step with eclipse. You might find this article interesting: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

Edit: So, the problem, apparently, was in the call to createBitmap being used to allocate the reflectionImage. Moral of the story (IMHO): never use createBitmap methods that do not allow you to explicitly specify Bitmap.Config. Otherwise, as Forrest Gump might say, you never know what you're gonna get.

可可 2024-11-14 08:39:13

我找到了应该设置配置的位置。创建反射位图时,将配置设置为 ARGB_8888。现在可以使用了。

I found the location where should I set the config. While creating the reflection bitmap set the config as ARGB_8888. Its working now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文