Loading only part of a bitmap file in Android

后端 未结 5 810
醉话见心
醉话见心 2020-12-14 19:14

I would like to load a cropped version of a bitmap image into a Bitmap object, without loading the original bitmap as well.

Is this at all possible without writing c

5条回答
  •  庸人自扰
    2020-12-14 20:14

    try this

    InputStream istream =   null;
    try {
         istream = this.getContentResolver().openInputStream(yourBitmapUri);
    } catch (FileNotFoundException e1) {
         e1.printStackTrace();
    }
    
    BitmapRegionDecoder decoder     =   null;
    try {
        decoder = BitmapRegionDecoder.newInstance(istream, false);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Bitmap bMap = decoder.decodeRegion(new Rect(istream, x to start from, y to start from, x to end with, y to end with), null);    
    imageView.setImageBitmap(bMap);
    

提交回复
热议问题