Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top