Hatch,

I investigated this issue myself yesterday!  My solution was pretty ugly,
I'll have to admit, but what I figured was that there's a color depth issue
when an ImageView is rendered over top something else. I ended up changing
my code so that the ImageView's parent would actually load the bitmap in and
draw it manually (in onDraw). So I had my ImageView in a RelativeLayout, so
I created a new class like this:

class MyRelativeLayout extends RelativeLayout {
...
  public void onDraw(Canvas c) {
    if(img == null) {
      // lazily load the image
      this.img =
(BitmapDrawable)getContext().getResources().getDrawable(R.drawable.image);
      this.p = new Paint();
    }
    c.drawImage(this.img.getImage(),0,0,p);
  }

}

In my layout xml file, I had basically this:
<MyRelativeLayout android:width="yourImageWidth"
android:height="yourImageHeight" android:background="#00000000" />

For my purposes I had to keep it as a RelativeLayout because I added other
children to it.. but if you really only need a single image, it doesn't need
to be a RelativeLayout object.

Anyway, I'm guessing there's a better work-around for decent alpha blending
between Views.

On Thu, Nov 4, 2010 at 9:35 AM, YuviDroid <yuvidr...@gmail.com> wrote:

> This might help:
> http://stuffthathappens.com/blog/2010/06/04/android-color-banding/
>
>
> YuviDroid
>
>
> On Thu, Nov 4, 2010 at 9:33 AM, Hatch <tomislav.hecimo...@gmail.com>wrote:
>
>> Great
>>
>> Your reply gives me hope :)
>>
>> But can you provide me with more information on how to do it ?
>>
>> I have a gradient alpha png.
>> I just use it in imageView inside an XML resource.
>> I don't set the dither option (although have tried both true and false
>> options with same result)
>> And I get the bands.
>>
>> Do I need to draw the image by hand, and which API must I use in that
>> case ?
>>
>> Regards,
>>
>> Hatch
>>
>>
>> On Nov 4, 1:19 am, Adam Hammer <adamhamm...@gmail.com> wrote:
>> > It get's banded because Android automatically decodes images based on
>> > your screen, and not based on the actual image. Why decode a 2048x2048
>> > image when it's showing on a 800x480 screen. This I assume is to save
>> > cpu cycles and speed up image decoding where it normally will not have
>> > a issue.
>> >
>> > When you are doing compositing though it does make a difference, and
>> > you need to be specific as to how you want the image decoded.
>> >
>> > Like I said before, you need to manually define your options to ensure
>> > it uses ARGB_8888 when decoding the image, disable dithering and
>> > scaling.
>> >
>> > Do this and you will no longer have banding.
>> >
>> > Adam
>> >
>> > On Nov 2, 1:01 am,Hatch<tomislav.hecimo...@gmail.com> wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > Yes, Thank you for your replies.
>> >
>> > > I have read the article but it doesn't explain why alpha enabled
>> > > resource get's banded :(
>> >
>> > > Is there a way to know exactly which RGB is used in the png ?
>> >
>> > > BTW the dither option didn't work in the XML nor in the code.
>> >
>> > > On Oct 30, 2:04 am, Lance Nanek <lna...@gmail.com> wrote:
>> >
>> > > > I saw an interesting article on avoiding this the other day:
>> http://android.nakatome.net/2010/04/bitmap-basics.html
>> >
>> > > > On Oct 29, 7:01 pm,Hatch<tomislav.hecimo...@gmail.com> wrote:
>> >
>> > > > > Seems my original post ("ugly pngs...") somehow disappeared :(
>> > > > > nvm.
>> >
>> > > > > I have a problem with a png resource that has gradient fade-out
>> alpha.
>> >
>> > > > > The png looks great in the emulator, but displays an artefact
>> known as
>> > > > > "color banding" (http://en.wikipedia.org/wiki/Colour_banding)
>> >
>> > > > > Has anyone surpassed this issue ?
>> >
>> > > > > My designer wants to trop a shadow behind his icons, and that's
>> where
>> > > > > the bands appear.
>> >
>> > > > > What are my options ?
>> >
>> > > > > Thanks
>> >
>> > > > >Hatch
>> >
>> > > > > BTW is there any way to see all my posts here on google groups ?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
>
> --
> YuviDroid
> Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget
> to quickly access your favorite apps and contacts!)
> http://android.yuvalsharon.net
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to