Such a problem ... I have a saved photo on the device, I need to show it to the user in the preview (so that he can see). The setImageUri() method setImageUri() not be used because it says that the image is larger than the ImageView can accept.
To do this, I open the file, get the bytes and convert them to a bitmap. And now I have a Bitmap , but how can I compress it?
The examples that I found describe the situation of compression only when we write to the file because Outputstrem needed for compression, but I read the file and I only have Inputstrem .
Tell me how to compress the image? Can it be compressed at the byte level?
Here is the code
File file = new File(params[0]); byte[] bytes = new byte[(int) file.length()]; FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream(file); bis = new BufferedInputStream(fis); long i = bis.read(bytes); System.out.println("Done !!!!!!!!!!!!!!!!!!!!!!!!! " + i); } catch (IOException e) { e.printStackTrace(); } finally { try { if (bis != null) { bis.close(); } if (fis != null) { fis.close(); } } catch (IOException e) { e.printStackTrace(); } } Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); // ΠΠ΄Π΅ΡΡ Π½ΡΠΆΠ½ΠΎ ΡΠΆΠ°ΡΡ Π±ΠΈΡΠΌΠ°ΠΏ ImageView image = (ImageView) findViewById(R.id.imageView); if (image != null) { image.setImageBitmap(bitmap); }