从采摘长廊,并显示出照片中的图像视图 [英] Picking a photo from gallery and show in a image view

查看:145
本文介绍了从采摘长廊,并显示出照片中的图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它有一个按钮,选择从您的画廊照片,并能正常工作,并选择图像后,我的应用程序秀回到了活动,并显示在图像查看图像。

每一个工作正常,但有时,当我选择一些特定的图像preVIEW没有显示。我也试图COM preSS的形象仍然是其无法正常工作

我的code低于.. 的onCreate()

  galeryBtn =(按钮)findViewById(R.id.buttonGallery);
galeryBtn.setOnClickListener(新OnClickListener(){

    @覆盖
    公共无效的onClick(视图v){
      意图I =新的意图(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(ⅰ,RESULT_LOAD_IMAGE);

    }
});
 

在onActivityResult(INT申请code,INT结果code,意图数据)

 如果(要求code == RESULT_LOAD_IMAGE和放大器;&安培;结果code == RESULT_OK和放大器;&安培;!空=数据){
    乌里selectedImage = data.getData();
    的String [] filePathColumn = {MediaStore.Images.Media.DATA};

    光标光标= getContentResolver()查询(selectedImage,filePathColumn,NULL,NULL,NULL);
    cursor.moveToFirst();

    INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
    字符串picturePath = cursor.getString(参数:columnIndex);
    cursor.close();
    //字符串picturePath包含所选图像的路径

    //显示在ImageView的所选择的图像
    ImageView的ImageView的=(ImageView的)findViewById(R.id.imgView);
    imageView.setImageBitmap(BitmapFactory.de codeFILE(picturePath));

}
 

解决方案

我碰上喜欢把光标URI从资源,打开的流,设置位图等类似的问题和它有缺陷,所有的时间。

所以,我搜索库,发现影像选择器 - 库库。

我敢打赌,你想尝试这个项目从影像选择器库

这是非常容易使用,解决了你所有的这些细节问题的问题,就像从Picasa等图像

希望这是对您有用。

I have an app, which has a button to select a photo from your gallery and it works fine and after selecting the image my app show came back to the activity and shows the image in an image View.

Every is working fine but sometimes ,when i select some particular images the preview is not showing. I have also tried to compress the image still its not working

My code is below.. In onCreate()

galeryBtn=(Button)findViewById(R.id.buttonGallery);
galeryBtn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
      Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(i, RESULT_LOAD_IMAGE);

    }
});

In onActivityResult(int requestCode, int resultCode, Intent data)

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
    Uri selectedImage = data.getData();
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();
    // String picturePath contains the path of selected Image

    // Show the Selected Image on ImageView
    ImageView imageView = (ImageView) findViewById(R.id.imgView);
    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

} 

解决方案

I run into similar problems like getting cursor uri from resource, open stream, set bitmap etc. And it has bugs all the time.

So I searched libraries and found image-chooser-library library.

I bet you would like to try this project from image-chooser-library

It is very easy to use and solves all those nitty gritty problems for you, like images from picasa etc.

Hopefully it is useful for you.

这篇关于从采摘长廊,并显示出照片中的图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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