【问题标题】:Unable to see the saved image as it looks in imageview无法看到保存的图像,因为它在 imageview 中看起来
【发布时间】:2013-07-08 10:37:45
【问题描述】:

我使用以下代码保存相机拍摄的图像

File storageDir= new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myphoto.png");//  getAlbumName()
FileOutputStream out = new FileOutputStream(storageDir);
ObjectOutputStream oos =new ObjectOutputStream(out);

mImageBitmap.compress(Bitmap.CompressFormat.PNG,100 , oos);
oos.flush();
oos.close();

我在“\pictures”文件夹中得到“myphoto.png”,但是当尝试打开图像时,我只能看到黑色窗口而不是图像。我错过了什么?谢谢

【问题讨论】:

  • 这不是 html。如果您指定正确的技术,可以帮助您的人会更容易。
  • 你试过 imageView.setImageBitmap(mImageBitmap) 吗?

标签: java android android-imageview android-image


【解决方案1】:

你不应该压缩成ObjectOutputStream oos,而是压缩成FileOutputStream outObjectOutputStream 用于 Java 对象,它会将不需要的数据添加到您的输出中。

File storageDir= new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myphoto.png");//  getAlbumName()
FileOutputStream out = new FileOutputStream(storageDir);

mImageBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多