Prevent bitmap too large to be uploaded into a texture android

后端 未结 6 1906
走了就别回头了
走了就别回头了 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:43

    i just created a if else function to check if the image is bigger than 1M pixels here's the sample code:

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    
       if (resultCode == RESULT_OK) {
    
         if (requestCode == SELECT_PICTURE) {
    
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;
    
            Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
            int height = bitmap.getHeight(), width = bitmap.getWidth();
    
            if (height > 1280 && width > 960){
                Bitmap imgbitmap = BitmapFactory.decodeFile(selectedImagePath, options);
                imageView.setImageBitmap(imgbitmap);
    
                System.out.println("Need to resize");
    
            }else {
                imageView.setImageBitmap(bitmap);
                System.out.println("WORKS");
            }
    

提交回复
热议问题