设置位图文件路径从ImageView的不工作 [英] Setting bitmap to imageview from filepath is not working

查看:122
本文介绍了设置位图文件路径从ImageView的不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过几乎所有可能的方法来设置图像到图像的视图从存储文件的路径。

他们没有工作。
从存储到数据库中的其它活动和画廊的ImagePath选择时的图像。

图像类型 .JPG .JPEG巴纽

存储在数据库路径没有任何扩展图像路径

 如。 /外部/存储/媒体/ carimagename

当我尝试图像设置为的ImageView 使用此code,没有错误,但图像没有被设置。

 的for(int i = 0; I< N;我++)
 {
 位图图片= BitmapFactory.de codeFILE(listview_arraypro1 [I]);
 carpict.setImageBitmap(PIC);    ///文件imgFile =新的文件(listview_arraypro1 [I]);
    // carpict.setImageBitmap(BitmapFactory.de codeFILE(imgFile.getAbsolutePath()));          //位图carpic = BitmapFactory.de codeStream(是);
          // carpic = Bitmap.createScaledBitmap(carpic,72,70,FALSE); }

如何设定路径格式 /外部/存储/媒体/ carimagename 图像到的ImageView

即时通讯使用以下命令获取$ p中$ pvious活动图像路径

 乌里selectedImage = imageReturnedIntent.getData();           串selectedImagePath = selectedImage.getPath();

难道我从selectedImagePath得到错误的路径?

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

 私人字符串getRealPathFromURI(URI contentURI){
    。光标光标= getContentResolver()查询(contentURI,NULL,NULL,NULL,NULL);
    如果(光标== NULL){//来源是Dropbox的或其他类似的本地文件路径
        返回contentURI.getPath();
    }其他{
        cursor.moveToFirst();
        INT IDX = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        返回cursor.getString(IDX);
    }
}    文件镜像文件=新的文件(getRealPathFromURI(selectedImage));
           字符串路径= imageFile.toString();


解决方案

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

然后后可以检索使用的ImagePath:

 字符串img_path =形象将与图像类型;
BMP位图= BitmapFactory.de codeFILE(img_path);
ImageView的IV =(ImageView的)findViewById(R.id.img);
iv.setImageBitmap(BMP);

您应该添加权限清单文件:

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAG​​E/>

I tried almost all methods possible to set image to a image-view from stored file path.

None of them work. The images were selected from gallery in other activity and imagepath stored into database.

Images are of type .jpg .jpeg .png

Image paths stored in database with paths without any extensions

eg.  /external/storage/media/carimagename

when I try to set image to imageview using this code there is no error but image is not set.

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

 }

How can i set the images with path format /external/storage/media/carimagename to an imageview?

Im using the following to get the image path in previous activity

             Uri selectedImage = imageReturnedIntent.getData();

           String  selectedImagePath = selectedImage.getPath();

Am i getting the wrong path from selectedImagePath?

this is the path i got using this which had no mnt/sdcard

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

解决方案

The main thing is that first you have to need mentioned your image type in your image path...

And after then you can retrieve using that 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);

you should add permission to manifest file:

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

这篇关于设置位图文件路径从ImageView的不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆