存储图像,然后在Android上的ImageView中显示它

时间:2011-03-11 20:04:19

标签: java android

我在android上构建一个应用程序,它显示存储在SD卡上特定文件夹中的图像。我希望我的代码在SD卡上构建文件夹,然后将图像文件放在该文件夹中。然后在创建它之后,我希望它将图像从文件夹中拉出并在imageview中显示它。这就是我到目前为止所做的。

    //create the folder then add the image here
    File SDlocation = Environment.getExternalStorageDirectory();
    File clothingdirectory = new File(SDlocation + "/images/");
    clothingdirectory.mkdirs();
    File outputFile = new File(clothingdirectory, imagename.png);
    FileOutputStream fos = new FileOutputStream(outputFile);

    //pull the image out of the folder here
    Bitmap bMap = BitmapFactory.decodeFile(SDLocation + "/images/imagename.png");
    ImageView iv = (ImageView) findViewById(R.id.imageView1);
    iv.setImageBitmap(bMap);
编辑:抱歉,我的问题是如何创建要保存在手机上的文件。我错过了一步。我没有名为imagename.png的图片。我将如何创建一个?

EDIT2:如何从我的项目文件夹中获取图像并将其放入我创建的目录中以便稍后撤出?

1 个答案:

答案 0 :(得分:1)

彼得,

您可以将图片放入drawable/文件夹,然后将ImageView设置为setImageDrawable(R.drawable.imagename)

相关问题