Load large images into Bitmap?

前端 未结 5 2234
耶瑟儿~
耶瑟儿~ 2021-01-02 09:23

I\'m trying to make a basic application that displays an image from the camera, but I when I try to load the .jpg in from the sdcard with BitmapFactory.decodeFile

5条回答
  •  余生分开走
    2021-01-02 09:47

    send:

                            BitmapFactory.Options o = new BitmapFactory.Options(); 
                        o.inJustDecodeBounds = true; 
                        BitmapFactory.decodeFile(filePath, o); 
    
                        int REQUIRED_SIZE = 640; 
                        int width_tmp = o.outWidth, height_tmp = o.outHeight; 
                        int scale = 1; 
                        while(true) { 
                            if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) break; 
                            width_tmp /= 2; 
                            height_tmp /= 2; 
                            scale *= 2; 
                        } 
    
                        BitmapFactory.Options o2 = new BitmapFactory.Options(); 
                        o2.inSampleSize = scale; 
                        Bitmap bitmap = BitmapFactory.decodeFile(filePath, o2); 
    
                        ByteArrayOutputStream bs2 = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.PNG, 90, bs2);
                        getIntent().putExtra("byte_picture", bs2.toByteArray());
    

    recive:

    Bitmap photo = BitmapFactory.decodeByteArray(data.getByteArrayExtra("byte_picture"),0,data.getByteArrayExtra("byte_picture").length);
    

提交回复
热议问题