Saving run-time generated NinePatch on external me

2019-09-03 03:11发布

问题:

I'm following this post to create nine patch drawable at run-time. I need to save the 9patch image on the internal/external memory, so that i can easily retrieve it's URI and assign it to an ImageView for example. Does anybody know how can I achieve this?

P.S. Bitmap.compress method won't work, because it will save the image as a regular (not 9patch) png file.

P.S. I know that I can serialize generated NinePatch object and save it to a file. But this way I can't assign it to a RemoteViews object (using RemoteViews.setImageViewUri method). So I need to save it as a real nine patch image.

回答1:

You can store the image as Bitmap and then create a NinePatch using http://developer.android.com/reference/android/graphics/NinePatch.html#NinePatch(android.graphics.Bitmap, byte[])