如何从SD卡中检索位图Arraylist

时间:2014-02-14 11:15:04

标签: android arraylist bitmap

在这里,我将图像分成9 * 9个片段,将所有片段放在这样的数组中,ArrayList值。接下来,我成功地将这些ArrayList值存储在sdcard中。这里我的问题是如何检索那些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;
            }
}

下面的代码存储了sdcard中的ArrayList值。

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);

那么现在,我如何从sdcard中检索那些ArrayList值“cut”并将它们存储在另一个/另一个ArrayList值中。 任何建议都要提前感谢

1 个答案:

答案 0 :(得分:0)

你做错了。

首先,你应该为arraylist中的每个位图命名(它可以像0.png,1.png,2.png等一样简单,具体取决于arraylist中位图的位置)并传递单个名称到FileOutputStream()构造函数而不是传递cut。传递cut没有任何意义,因为提到的构造函数应该接收单个文件名。

请勿忘记在out.close()之后致电selectedphoto_bitmap.compress(...)

为了阅读位图,你可以做类似的事情:

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);
}