Captured Image Resolution is too big

后端 未结 2 1222
-上瘾入骨i
-上瘾入骨i 2021-01-28 21:51

What I am Doing ?

I am allowing user to capture image, storing it into SD Card and uploading to server.

But getting resolution of Captured image

2条回答
  •  既然无缘
    2021-01-28 22:45

    use FileOutputStream.flush() after writing data...

    File file = new File(fileName.toString());
    try {
        FileOutputStream stream = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, stream);
        stream.flush();
        stream.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
    

    You can save Bitmap image following code

    Bitmap photo = (Bitmap) "your Bitmap image";
    photo = Bitmap.createScaledBitmap(photo, 100, 100, false);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
    
    File f = new File(Environment.getExternalStorageDirectory()
            + File.separator + "Imagename.jpg");
    f.createNewFile();
    FileOutputStream fo = new FileOutputStream(f);
    fo.write(bytes.toByteArray());
    fo.close();
    

提交回复
热议问题