我需要以编程方式在我的Android应用程序上创建.jpeg/.png文件。我有简单的图像(黑色背景),它需要编写一些文本编程。我该怎么做?可能吗?是否可以在Java,Android上以编程方式创建图像?
13
A
回答
6
是,see here
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
您还可以使用AWT的Graphics2D的与this compatibility project
7
这是肯定可以的。
要在图像上写入文本,必须将图像加载到Bitmap对象中。然后用Canvas和Paint函数绘制该位图。完成绘图后,只需将位图输出到文件即可。
如果您只是使用黑色背景,最好在画布上创建空白位图,填充黑色,绘制文本然后转储到位图。
I used this tutorial to learn the basics of the canvas and paint.
这就是你要寻找的代码把画布中的图像文件:
OutputStream os = null;
try {
File file = new File(dir, "image" + System.currentTimeMillis() + ".png");
os = new FileOutputStream(file);
finalBMP.compress(CompressFormat.PNG, 100, os);
finalBMP.recycle(); // this is very important. make sure you always recycle your bitmap when you're done with it.
screenGrabFilePath = file.getPath();
} catch(IOException e) {
finalBMP.recycle(); // this is very important. make sure you always recycle your bitmap when you're done with it.
Log.e("combineImages", "problem combining images", e);
}
+0
如何在JavaScript中做同样的事情?任何图书馆或任何可以帮助我们做到这一点的东西? – Chetan
6
使用Graphics2d
你可以创建一个PNG图像,以及:
public class Imagetest {
public static void main(String[] args) throws IOException {
File path = new File("image/base/path");
BufferedImage img = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.YELLOW);
g2d.drawLine(0, 0, 50, 50);
g2d.setColor(Color.BLACK);
g2d.drawLine(50, 50, 0, 100);
g2d.setColor(Color.RED);
g2d.drawLine(50, 50, 100, 0);
g2d.setColor(Color.GREEN);
g2d.drawLine(50, 50, 100, 100);
ImageIO.write(img, "PNG", new File(path, "1.png"));
}
}
相关问题
- 1. 以编程方式在图像上创建可点击区域
- 2. 以编程方式创建图像?
- 3. 以编程方式在android中创建透明图像
- 4. 以编程方式创建流程图
- 5. 是否有可能以编程方式创建BackgroundWorkers?
- 6. 是否有可能以编程方式创建Google API KEY?
- 7. 是否有可能以编程方式创建散列规则?
- 8. Android:以编程方式创建TextView
- 9. Android创建列表以编程方式
- 10. Android以编程方式创建ViewPager
- 11. 以编程方式创建图像的最佳方式
- 12. 是否有可能以编程方式在iPhone上创建符号链接?
- 13. 是否可以在Android中以编程方式设置锁屏背景图片?
- 14. 以编程方式创建视图
- 15. 试图以编程方式创建rightBarButtonItem
- 16. 以编程方式创建绘图
- 17. 以编程方式创建视图
- 18. 以编程方式创建UML类图
- 19. 以编程方式在媒体库下创建图像
- 20. 以编程方式创建拨号图像的最佳方法?
- 21. 以编程方式创建ImageView并在画布上绘制android
- 22. 是否可以通过Chrome以编程方式创建虚拟MIDI设备?
- 23. 是否可以通过iPhone以编程方式创建.xls文件?
- 24. 是否可以使用DBX以编程方式创建数据库?
- 25. 以编程方式在Android中创建列表视图项目
- 26. 以编程方式创建图像的缩略图
- 27. Android:以编程方式在图像上突出显示效果
- 28. 你可以在C#中以编程方式创建表单域?
- 29. 以编程方式在Linux服务器上创建Visio绘图
- 30. 是否可以在PHP中以编程方式启用扩展?
重复http://stackoverflow.com/questions/8025728/how-to-create-simple-image-programatically – Suragch