简体   繁体   中英

How to select GIF from gallery and show it in image-view

How to select both normal and gif images from the gallery, and how to set condition whether the image selected is a gif or an image?

Below is the code where the image is selected from the gallery and is set in the PhotoView which is inside FrameLayout .The code MediaStore.Images.Media.getBitmap() is used to select images from the gallery but how to select gif from the gallery and how to set check condition after the image is selected that whether that selected image is a gif or simple image

    PhotoView iv_add_player;
    String playerimagesave;
    Uri uri = data.getData();
    Glide.with(this).load(uri).into(iv_add_player);
    Bitmap bm = null;
    try {
    bm=MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
    //How to set Gif in above line??                  
      } 
    catch (IOException e){
    e.printStackTrace();
      }
    playerimagesave = getImage(bm);
    iv_add_player.setImageBitmap(bm);

The above code is for the selection of gallery images but how to set gif images from gallery?

This onActivityResult(int requestCode, int resultCode, Intent data){} function has the above code and is used here below-

            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, 2);

You can use the latest Glide Library to show the gif, below is the code for reference:

GlideApp  
    .with(context)
    .asGif()
    .load(uri)
    .into(imageView);

This will solve your problem of showing gif bitmap in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM