Never thought I'd be worthy of a response from the man himself.
The thing that had me stumped was it was working on some drawables but
not others.
I now have another issue with it... the reason I was having trouble
was trying to use the ldpi/mdpi/hdpi assets. It now uses these assests
and selects the correct one however it scales it as if it is an mdpi
image. See this image: http://edschache.com/ldpi_hdpi_issue.png This
was done by marking each png with it's size, creating a menuicon2 from
the mdpi version and putting it in /drawable/. As you can see using
the mdpi version results in the same size icon as the hdpi and ldpi
icons. The same brush width was used for marking all 3 images.
images:
http://edschache.com/ldpi_menuicon.png
http://edschache.com/mdpi_menuicon.png
http://edschache.com/hdpi_menuicon.png
Does this mean that I need to scale the images manually anyway? I was
hoping that getResources().getDrawable(R.drawable.menuicon) would
automatically get the correct drawable at the correct scale per the
info icon next to it. It selects the correct image but gets the scale
wrong. The images in the various dpi folders are the correct
resolution and .png format.
For anyone else stuck on this here's the code that I got working to
make the images drawable (still has the scaling issue):
Drawable d = getResources().getDrawable(R.drawable.menuicon);
Bitmap bOriginal = ((BitmapDrawable) d).getBitmap();
Bitmap bMutable = bOriginal.copy(Bitmap.Config.ARGB_8888, true);
BitmapDrawable dMutable = new BitmapDrawable(bMutable);
Canvas c = new Canvas(bMutable);
//draw on canvas
d.draw(c);
mi.setIcon(dMutable);
On Aug 30, 7:05 pm, Romain Guy <romain...@android.com> wrote:
> Mutating a drawable does not making the Bitmap it may contain mutable.
> You have to check whether the Bitmap you get is mutable. Bitmaps
> loaded from resources are never mutable, you must create a mutable
> copy first (see the Bitmap.create/copy documentation.)
>
>
>
>
>
> On Mon, Aug 30, 2010 at 12:53 AM, Ed <edscha...@gmail.com> wrote:
> > Hi all,
>
> > Found a bit of a weird one which might be related to this post -
> >http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > I've check the public issue tracker for android and can't see anything
> > related to this.
>
> > Basically I'm setting an icon in a menu, getting a mutable copy of the
> > icon, drawing some text on it to create a menu item that reflects the
> > current state of the thing the menu item links to.
>
> > This works all well and good when I use a resource that is in /
> > drawble/ but if I put the same resource into /drawable/hdpi/ (with
> > relevant resizes in ldpi and mdpi) it blows up saying that it is not
> > mutable... even though it's using the same code and the same image
> > format (exactly the same file):
>
> > Drawable d = mi.getIcon().mutate();
> > Canvas c = new Canvas(((BitmapDrawable) d).getBitmap());
> > //draw on canvas
> > d.draw(c);
>
> > I wish to use the different dpi graphics as appropriate rather than
> > scaling at runtime or implementing my own dpi image selector. Is this
> > a known limitation? If so is there documentation about it?
>
> > Cheers,
>
> > Ed
>
> > --
> > 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+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Romain Guy
> Android framework engineer
> romain...@android.com
>
> Note: please don't send private questions to me, as I don't have time
> to provide private support. All such questions should be posted on
> public forums, where I and others can see and answer them
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment