从采摘长廊,并显示出照片中的图像视图长廊、视图、片中、图像

2023-09-08 08:48:20 作者:清新文艺的,清新淡雅的

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

每一个工作正常,但有时,当我选择一些特定的图像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.