在这里,我将图像分成9*9个部分,将所有部分放在一个数组中,就像这样,ArrayList值。然后,我成功地将这些ArrayList值存储在SD卡中。这里我问题是如何检索这些ArrayList值,而在Arraylist值中包含一些分隔符图像。你可以在下面观察细节。
ArrayList<Bitmap> cut = new ArrayList<Bitmap>(number_bixs);
Bitmap Bb = Bitmap.createScaledBitmap(Bsbmp, width,height, true);
rows = cols = (int) Math.sqrt(number_bixs);
hgt = Bb.getHeight() / rows;
wdt = Bb.getWidth() / cols;
int yaxis = 0;
for (int x = 0; x < rows; x++) {
int xaxis = 0;
for (int y = 0; y < cols; y++) {
cut.add(Bitmap.createBitmap(Bb, xaxis, yaxis, wdt, hgt));
xaxis += wdt;
}
}下面代码将ArrayList值存储在SD卡中。
File FracturedDirectory = new File(
Environment.getExternalStorageDirectory()
+ "/Fractured photoes/");
FracturedDirectory.mkdirs();
try {
FileOutputStream out = new FileOutputStream(Environment
.getExternalStorageDirectory().toString()
+ "/Fractured photoes/" + cut);
selectedphoto_bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);那么,我如何从SD卡中检索那些ArrayList值"cut“,并将它们存储在一个或多个ArrayList值中呢?如有任何建议,请提前感谢
发布于 2014-02-14 19:38:36
你做错了几件事。
首先,您应该为arraylist中的每个位图指定一个名称(根据位图在arraylist中的位置,可以简单到0.png、1.png、2.png等),并将各个名称传递给FileOutputStream()构造函数,而不是传递cut。传递cut没有任何意义,因为前面提到的构造函数应该只接收一个文件名。
别忘了在selectedphoto_bitmap.compress(...)之后调用out.close()。
为了读取位图,您可以执行类似以下操作:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
for (int i = 0; i < 81; i++) {
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
cut.add(bitmap);
}https://stackoverflow.com/questions/21777876
复制相似问题