我有一个基本图像视图,可以从 sd 卡加载图像。用户可以templates(bitmap images)
通过单击按钮添加到此图像视图,并且可以根据用户需要定位添加的图像。我想将这些多个图像作为单个图像保存到 sd 卡。我怎样才能做到这一点?
问问题
1989 次
2 回答
3
您可以简单地获取 ImageView 的 DrawingCache,然后将其转换为 Bitmap,然后将其保存到 SDCARD。
imageview.setDrawingCacheEnabled(true);
Bitmap b = imageview.getDrawingCache();
b.compress(CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/image.jpg"));
您可能必须在清单中设置 SDCARD 写入权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
于 2012-07-03T07:52:34.567 回答
3
看看这个片段:
int rows = 2; //we assume the no. of rows and cols are known and each chunk has equal width and height
int cols = 2;
int chunks = rows * cols;
int chunkWidth, chunkHeight;
int type;
//fetching image files
File[] imgFiles = new File[chunks];
for (int i = 0; i < chunks; i++) {
imgFiles[i] = new File("archi" + i + ".jpg");
}
//creating a bufferd image array from image files
BufferedImage[] buffImages = new BufferedImage[chunks];
for (int i = 0; i < chunks; i++) {
buffImages[i] = ImageIO.read(imgFiles[i]);
}
type = buffImages[0].getType();
chunkWidth = buffImages[0].getWidth();
chunkHeight = buffImages[0].getHeight();
//Initializing the final image
BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type);
int num = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null);
num++;
}
}
System.out.println("Image concatenated.....");
ImageIO.write(finalImg, "jpeg", new File("finalImg.jpg"));
于 2012-07-03T07:54:30.647 回答