3

我在里面有一个 jpg 图像作为字节数组。我如何将此字节数组转储到 jpg 并在其画布上写入,然后将其保存在 sd 卡上?

欢迎任何想法。谢谢。

4

2 回答 2

4

使用BitmapFactory.decodeByteArray()获取一个Bitmap,然后Canvas使用该位图创建一个,并在那里绘制文本。最后使用以下方法保存Bitmap.compress()

Bitmap bmp = BitmapFactory.decodeByteArray(myArray, 0, myArray.length).copy(Bitmap.Config.RGBA_8888, true); //myArray is the byteArray containing the image. Use copy() to create a mutable bitmap. Feel free to change the config-type. Consider doing this in two steps so you can recycle() the immutable bitmap.
Canvas canvas = new Canvas(bmp);
canvas.drawText("Hello Image", xposition, yposition, textpaint); //x/yposition is where the text will be drawn. textpaint is the Paint object to draw with.

OutputStream os = new FileOutputStream(dstfile); //dstfile is a File-object that you want to save to. You probably need to add some exception-handling here.
bmp.compress(CompressFormat.JPG, 100, os); //Output as JPG with maximum quality.
os.flush();
os.close();//Don't forget to close the stream.
于 2012-04-24T12:46:21.400 回答
2
  1. 使用BitmapFactory解码字节数组
    1. 创建画布
    2. 在上面画文字
    3. 将位图保存SD 存储

希望这可以帮助。

于 2012-04-24T12:45:05.817 回答