为了账号安全,请及时绑定邮箱和手机立即绑定

图像未以原始分辨率保存

图像未以原始分辨率保存

FFIVE 2021-12-18 09:54:38
这是以非常低的分辨率保存图像的代码。来自 url 的图像太大但是当我通过此代码保存图像时,它会减小图像的大小和分辨率private void saveImage(final String uri) throws IOException,  IllegalStateException { URL url = new URL(uri); InputStream input = url.openStream(); File storagePath = Environment.getExternalStorageDirectory(); OutputStream output = new FileOutputStream(storagePath + "/myImage.png"); try {   byte[] buffer = new byte[2048];   int bytesRead = 0;   while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {     output.write(buffer, 0, bytesRead);   } } finally {   output.close(); }
查看完整描述

1 回答

?
ibeautiful

TA贡献1993条经验 获得超6个赞

尝试如下:


Bitmap bitmapImage; //your input bitmap to save   


File storagePath = Environment.getExternalStorageDirectory();

OutputStream output = new FileOutputStream(storagePath + "/myImage.png")


try {           

    // Use the compress method on the BitMap object to write image to the OutputStream

    bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, output);

} catch (Exception e) {

    e.printStackTrace();

} finally {

    try {

        output.close();

    } catch (IOException e) {

        e.printStackTrace();

    }

}


查看完整回答
反对 回复 2021-12-18
  • 1 回答
  • 0 关注
  • 196 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号