首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jpg图像上绘制文本

在jpg图像上绘制文本
EN

Stack Overflow用户
提问于 2012-04-24 20:38:57
回答 2查看 2.7K关注 0票数 3

我有一个作为字节数组的jpg图像。我如何将这个字节数组转储到一个jpg中并写入到它的canavas中,然后将其保存到SD卡上?

欢迎任何想法。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-24 20:46:21

使用BitmapFactory.decodeByteArray()获取一个Bitmap,然后使用该位图创建一个Canvas,并在其中绘制文本。最后,使用Bitmap.compress()保存它

代码语言:javascript
复制
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.
票数 4
EN

Stack Overflow用户

发布于 2012-04-24 20:45:06

  1. 解码字节数组使用BitmapFactory
    1. Create a bitmap text on SD storage

to SD storage

  1. toSD storage

希望这能有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10297986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档