从字符串到图像的转换

时间:2011-03-10 14:55:51

标签: android android-imageview

  

可能重复:
  Show Image View from file path in android?

这里图像路径存储为字符串我想将字符串转换为图像并需要在模拟器中查看图像这怎么可能?请告诉我

感谢

3 个答案:

答案 0 :(得分:0)

使用ImageView并将您的字符串添加为资源。

答案 1 :(得分:0)

Bitmap bm = BitmapFactory.decodeFile(mImagePath);
ImageView image = (ImageView) findViewById(R.id.image_view);
image.setImageBitmap(bm);

假设mImagePath是包含路径的字符串,R.id.image_view是您布局中ImageView的ID。

祝你好运!

答案 2 :(得分:0)

answer可能有所帮助。从那个答案:

File imgFile = new  File(“/sdcard/Images/test_image.jpg”);
if(imgFile.exists()){
    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile);
    ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
    myImage.setImageBitmap(myBitmap);
}