1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Padma
  • 656
  • 3
  • 11
  • 30

2 Answers2

4

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.

George Freeman
  • 2,260
  • 1
  • 15
  • 22
  • Hi George, thanks for your reply, I know that I want to set the config as ARGA_8888, but its not working, the thing is I should know the place where exactly I have to set the config. I tried the following -BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; then also it is not working. – Padma May 17 '11 at 09:33
1

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

Padma
  • 656
  • 3
  • 11
  • 30