android Image view out of memory error

后端 未结 5 1687
一整个雨季
一整个雨季 2021-01-25 06:43

In my Android project I have imageButton , and after clicking on it , it must open new Activity with imageView , and in my new Activity I must see the ImageButton\'s image only

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-25 07:29

    below code can help you for resize an Image

    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                    File output = new File(dir, "image.png");
    
    
        path = output.getAbsolutePath();
        Bitmap b =  BitmapFactory.decodeFile(cPath);
        Bitmap out = Bitmap.createScaledBitmap(b, 320, 480, false);
        FileOutputStream fout;
        try{
            fout = new FileOutputStream(output);
            out.compress(Bitmap.CompressFormat.PNG, 100, fout);
            fout.flush();
            fout.close();
            b.recycle();
            out.recycle();
        }catch(Exception e){
            e.printStackTrace();
        }
    

提交回复
热议问题