getting Image ThumbNail in Android

前端 未结 4 1460
北荒
北荒 2020-12-28 08:52

I need Thumbnail of an image . I only know about the name of image which is stored in SD card . Can anyone help me.

4条回答
  •  时光说笑
    2020-12-28 09:06

    byte[] imageData = null;
    
    try
    {
    
    final int THUMBNAIL_SIZE = 64;
    
    FileInputStream fis = new FileInputStream(fileName);
    Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
    
    Float width = new Float(imageBitmap.getWidth());
    Float height = new Float(imageBitmap.getHeight());
    Float ratio = width/height;
    imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
    
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    imageData = baos.toByteArray();
    
    }
    catch(Exception ex) {
    
    } 
    

提交回复
热议问题