views:

88

answers:

1

I have a widget with an ImageView on it. I set this ImageView to a Bitmap created from a 9-patch PNG resource. The image is set correctly but is not stretched correctly - i.e. the whole image is stretched instead of just part like defined in my 9-patch PNG. If I just set the 9-patch image as a resource, it works. How can I fix this?

// Does not work (9-patch does not display correctly)
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.someNinePatch);
remoteViews.setImageViewBitmap(R.id.someImageView, bitmap);

// Works (9-patch displays correctly)
remoteViews.setImageViewResource(R.id.someImageView, R.drawable.someNinePatch);
A: 

Android knows a PNG is a nine-patch by virtue of the .9.png file extension on the resource. I do not know of any way to use nine-patch images outside of resources, because Android will not have the file extension and will not know the image is a nine-patch.

CommonsWare
The resource does have the .9.png extension, I am just using it as a bitmap instead.
Isaac Waller
@Isaac Walter: but you're losing the extension by loading it into a `Bitmap` object. AFAIK, a `Bitmap` object has no idea whether it came from a regular PNG, a nine-patch PNG, a JPEG, a GIF, or something else.
CommonsWare