图像不会保存在不同的 Android 设备上

发布于 2024-11-18 14:05:33 字数 753 浏览 6 评论 0原文

我正在使用此代码来保存从屏幕截图中获取的位图图像:

try{
    String fname = "/Pictures/YourApp/YourPic.jpg";
    File path= Environment.getExternalStorageDirectory();
    File file = new File(path, fname);
    if (file.exists()) {
                Bitmap bitty = BitmapFactory.decodeFile(file.toString());
                    yourPlan.setImageBitmap(bitty); //ImageView
            }else{
                errorText.setText("If you can not see your image then free up some memory");
            }
        }catch(Exception e){
                errorText.setText("If you can not see your image then free up some memory");
        }

它在我的测试手机(2.1 上的 Orange San Francisco)上运行良好,但我收到用户的电子邮件告诉我,他们只有在保存足够的空间时才会收到错误消息。

他们使用 HTC 和三星手机。有什么想法吗?

I am using this code to save a bitmap image taken from a screen shot:

try{
    String fname = "/Pictures/YourApp/YourPic.jpg";
    File path= Environment.getExternalStorageDirectory();
    File file = new File(path, fname);
    if (file.exists()) {
                Bitmap bitty = BitmapFactory.decodeFile(file.toString());
                    yourPlan.setImageBitmap(bitty); //ImageView
            }else{
                errorText.setText("If you can not see your image then free up some memory");
            }
        }catch(Exception e){
                errorText.setText("If you can not see your image then free up some memory");
        }

It works fine on my testing phone - an Orange San Francisco on 2.1 but I have had emails from users telling me they only get the error message when saving with enough space.

They are using HTC and Samsung handsets. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2024-11-25 14:05:33

首先,我想指出,捕获一般的 Exception e 并不是良好的编码实践。其次,您输出给用户的两条消息也没有帮助,因为不能保证错误与空间相关。

我猜测错误来自于文件不存在。你把文件保存在哪里?从代码片段中,我发现您只是假设该文件存在。如果您在拍摄屏幕截图后尚未保存文件,那么这就是您的问题。您正在打开一个不存在的文件,并且您的错误消息给人一种空间不足的错误印象。

First, I would like to point out that catching a general Exception e is not in good coding practice. Second, both messages you output to the user are also not helpful as it is not guaranteed that the error is space-related.

I am guessing the error comes from the file not existing. Where are you saving the file? From the snippet of code, I see that you are simply assuming the file exists. If you haven't yet saved the file after taking your screen shot, that would be your problem right there. You are opening a file that doesn't exist and your error message is giving the mistaken impression that there isn't enough space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文