Prevent bitmap too large to be uploaded into a texture android

后端 未结 6 1969
走了就别回头了
走了就别回头了 2021-01-17 10:02

I need to display original image in full screen in gallery form. For thumb it will be work perfectly and when I try to display that image in full screen with original source

6条回答
  •  自闭症患者
    2021-01-17 10:19

    I found a way to do this without using any external libraries:

    if (bitmap.getHeight() > GL10.GL_MAX_TEXTURE_SIZE) {
    
        // this is the case when the bitmap fails to load
        float aspect_ratio = ((float)bitmap.getHeight())/((float)bitmap.getWidth());
        Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0,
                        (int) ((GL10.GL_MAX_TEXTURE_SIZE*0.9)*aspect_ratio),
                        (int) (GL10.GL_MAX_TEXTURE_SIZE*0.9));
        imageView.setImageBitmap(scaledBitmap);
    }
    else{
    
        // for bitmaps with dimensions that lie within the limits, load the image normally
        if (Build.VERSION.SDK_INT >= 16) {
            BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap);
            imageView.setBackground(ob);
        } else {
            imageView.setImageBitmap(bitmap);
        }
    }
    

    Basically, the maximum image dimensions are a system-imposed limit. The above approach will correctly resize bitmaps that exceed this limit. However, only a portion of the entire image will be loaded. To change the region displayed, you can alter the x and y parameters of the createBitmap() method.

    This approach handles bitmaps of any size, including pictures taken with professional cameras.

    References:

    Android Universal Image Loader.

提交回复
热议问题