将运行时生成的NinePatch保存在外部存储器上 [英] Saving run-time generated NinePatch on external memory
问题描述
我正在关注这篇文章以创建九个可绘制的补丁在运行时.我需要将9patch图像保存在内部/外部存储器上,以便我可以轻松地检索它的URI并将其分配给例如ImageView.有人知道我该怎么做到吗?
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
方法不起作用,因为它将图像保存为常规(不是9patch)png文件.
P.S. Bitmap.compress
method won't work, because it will save the image as a regular (not 9patch) png file.
P.S.我知道我可以序列化生成的NinePatch对象并将其保存到文件中.但是这种方式不能将其分配给RemoteViews对象(使用RemoteViews.setImageViewUri方法).因此,我需要将其保存为真实的九个补丁映像.
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.
推荐答案
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[])
这篇关于将运行时生成的NinePatch保存在外部存储器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!