问题:何时在 SD 卡上保存可绘制对象或位图?

发布于 2024-12-20 08:33:21 字数 859 浏览 2 评论 0原文

我正在尝试将图像保存在 SD 卡中,如下所示:

Bitmap bitmap=Bitmap.createBitmap(400, 300, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bitmap);
imageView.draw(canvas);


 file = new File(folder, "temp.jpg");
 try {
        outStream = new FileOutputStream(file);
        bitmapP.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
        return file.toString();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    }

现在我得到的图像如下所示:

Bitmap bitmap = BitmapFactory.decodeFile(image);

我有位图,但我的位图质量变得模糊...... 我做错了什么?

任何人都可以帮助我吗? 谢谢

I am trying to save image in sd card like as :

Bitmap bitmap=Bitmap.createBitmap(400, 300, Bitmap.Config.ARGB_8888);
Canvas canvas=new Canvas(bitmap);
imageView.draw(canvas);


 file = new File(folder, "temp.jpg");
 try {
        outStream = new FileOutputStream(file);
        bitmapP.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
        return file.toString();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;

    }

Now i get image like as:

Bitmap bitmap = BitmapFactory.decodeFile(image);

I got bitmap, But my bitmap quality is going blur...
What's i doing wrong ?

Any one can help me?
thanks

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

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

发布评论

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

评论(2

小嗲 2024-12-27 08:33:21

JPEG 不是无损格式。有点模糊是正常的。其他选项有 Bitmap.compressFormat.WEBP 和位图.压缩格式.PNG

JPEG is not a lossless format. It is normal that it gets blurred little bit. Other options are Bitmap.CompressFormat.WEBP & Bitmap.CompressFormat.PNG

离旧人 2024-12-27 08:33:21

尝试从文件中获取位图,如下所示:

 bitmap= BitmapFactory.decodeStream(file.toURL().openStream());

希望这会对您有所帮助!如果您还没有找到答案!

try to get bitmap from file like this:

      bitmap= BitmapFactory.decodeStream(file.toURL().openStream());

hope this will help you! if you haven't already found an answer!

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