2013-08-27 31 views
0

我尝试了几乎所有可能的方法,将图像从存储的文件路径设置为image-view从文件路径设置位图到imageview不起作用

没有一个工作。 图像是从其他活动的图库中选择的,图像路径存储在数据库中。

图像是类型的.JPG存储在数据库的路径而没有任何扩展的.jpeg .PNG

图像路径

eg. /external/storage/media/carimagename 

当我尝试使用此代码图像设置为imageview没有错误,但图像未设置。

for(int i=0;i<n;i++) 
{ 
Bitmap pic = BitmapFactory.decodeFile(listview_arraypro1[i]); 
carpict.setImageBitmap(pic); 

    /// File imgFile =new File("listview_arraypro1[i]"); 
    // carpict.setImageBitmap(BitmapFactory.decodeFile(imgFile.getAbsolutePath())); 



      // Bitmap carpic = BitmapFactory.decodeStream(is); 
      // carpic = Bitmap.createScaledBitmap(carpic, 72, 70, false); 

} 

我怎么可以设定路径格式/external/storage/media/carimagename图像到imageview

即时通讯使用下列以获得在以前的活动图像路径

   Uri selectedImage = imageReturnedIntent.getData(); 

      String selectedImagePath = selectedImage.getPath(); 

我收到来自selectedImagePath走错路?

这是我得到了使用此路径它没有MNT/SD卡

private String getRealPathFromURI(Uri contentURI) { 
    Cursor cursor = getContentResolver().query(contentURI, null, null, null, null); 
    if (cursor == null) { // Source is Dropbox or other similar local file path 
     return contentURI.getPath(); 
    } else { 
     cursor.moveToFirst(); 
     int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
     return cursor.getString(idx); 
    } 
} 



    File imageFile = new File(getRealPathFromURI(selectedImage)); 
      String path= imageFile.toString(); 

回答

4

主要的事情是,首先,你必须在你的图像路径需要提到你的图像类型...

再之后,你可以检索使用的ImagePath:

String img_path = "image will be with image type";  
Bitmap bmp= BitmapFactory.decodeFile(img_path); 
ImageView iv= (ImageView)findViewById(R.id.img); 
iv.setImageBitmap(bmp); 

你应该添加清单文件的权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
+0

没有答案工作:(还尝试给图像路径字符串img _path =“/ storage/sdcard0/Fbt/xylo.jpg”;仍然没有工作! – Metalhead1247

+0

你有没有为它添加权限? – Piyush

+0

哪个特权? – Metalhead1247

1
Image paths stored in database with paths without any extensions 

您需要提及的路径图像类型。即image.png

你可以尝试像下面的例子。

String imagePath = "your image path with image type"; //eg. /sdcard/img.PNG  
    Bitmap bitmap = BitmapFactory.decodeFile(imagePath); 
    ImageView myImageView = (ImageView)findViewById(R.id.imageview);// your imageview 
    myImageView.setImageBitmap(bitmap); 
2

this处取一个雄g。

您可以使用ImageView.setImageURI(..)方法。

preview.setImageURI(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Echo/Images/"+file_name));