【发布时间】:2014-08-26 14:23:29
【问题描述】:
我正在尝试编写一个元胞自动机程序来处理数组中的整数值,然后将数组显示为图像。
整数数组 --> 图像 --> 显示在屏幕上
我尝试过 BitmapFactory.decodeByteArray() 和 Bitmap.createBitmap(),但所有示例都需要将现有的 .jpg 或 .png 读取到 byte[] 中,然后将其转换回位图。
有没有人有一个从头开始构建数组、转换为图像然后显示的清晰示例?即使是 50x50 像素的完全蓝色正方形的最简单示例也会有所帮助。
如果 BitmapFactory.decodeByteArray() 不是最佳选择,我愿意接受任何替代方案。
谢谢!
到目前为止,我的代码来自 onClick() 方法:
display = (ImageView) findViewById(R.id.imageView1);
Bitmap bMap = null;
int w = 50, h = 50; // set width = height = 50
byte[] input = new byte[w * h]; // initialize input array
for (int y = 0; y < h; y++) { // fill input with blue
for (int x = 0; x < w; x++) {
input[y * w + x] = (byte) Color.BLUE;
}
}
bMap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length, Bitmap.Config.ARGB_8888); // convert byte array to bitmap
display.setImageBitmap(bMap); // post bitmap to imageview
【问题讨论】:
标签: android arrays image bitmap bitmapfactory