在android中将base64转换为9补丁.png


convert base64 into 9 patch .png in android

我正试图将php服务器上的几个图像发送到我的应用程序。这些图像是9个patch.png文件。为此,在我的服务器上,我使用base64:进行编码

$img = fread(fopen($filepath, "r"), filesize($filepath));
$bin_image = base64_encode($img);

稍后,我将其打包为json,并将其发送到我的应用程序:

echo json_encode($response);

在我的android应用程序上,我从响应的json:中获取图像

public ServerMsg(JSONObject response, ServerResponseTags responseTag) throws JSONException {
    ...
    String image_str = response.getString(IMAGE);
    byte[] imageAsBytes = Base64.decode(image_str.getBytes(), Base64.DEFAULT);
    image = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
    ...
}

问题是,图像没有按照我的需要显示为9补丁png文件。我知道我需要将位图图像转换为png9补丁文件,但我不知道如何。。。有什么建议吗?

我在这篇文章中找到了解决方案:在运行时创建一个NinePatch/NinePatchDrawable,我很快就使用Brian Griffey类将位图转换为九个补丁。。。