首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从SD卡中检索位图数组列表

如何从SD卡中检索位图数组列表
EN

Stack Overflow用户
提问于 2014-02-14 19:15:04
回答 1查看 561关注 0票数 0

在这里,我将图像分成9*9个部分,将所有部分放在一个数组中,就像这样,ArrayList值。然后,我成功地将这些ArrayList值存储在SD卡中。这里我问题是如何检索这些ArrayList值,而在Arraylist值中包含一些分隔符图像。你可以在下面观察细节。

代码语言:javascript
运行
复制
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卡中。

代码语言:javascript
运行
复制
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值中呢?如有任何建议,请提前感谢

EN

Stack Overflow用户

发布于 2014-02-14 19:38:36

你做错了几件事。

首先,您应该为arraylist中的每个位图指定一个名称(根据位图在arraylist中的位置,可以简单到0.png、1.png、2.png等),并将各个名称传递给FileOutputStream()构造函数,而不是传递cut。传递cut没有任何意义,因为前面提到的构造函数应该只接收一个文件名。

别忘了在selectedphoto_bitmap.compress(...)之后调用out.close()

为了读取位图,您可以执行类似以下操作:

代码语言:javascript
运行
复制
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);
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21777876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档