我无法使用 MS Paint 在 sdk 上将位图保存为 jpg 文件打开

发布于 2024-12-28 08:36:48 字数 608 浏览 1 评论 0原文

我将位图保存为 jpg 文件。源代码是:

imageView = new ImageView(this);
bitmap = Bitmap.createBitmap(d.getWidth() ,d.getHeight() , Bitmap.Config.ARGB_8888);
canvas = new Canvas (bitmap);

iv.setDrawingCacheEnabled(true);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/mrun.jpg")));

我在模拟器上测试它。文件已保存,大小约为 150 Kb。但是,如果我想使用 MS Paint 等任何程序打开它,我会收到错误消息。我想念什么?谢谢。 评论:我尝试写以下行而不是最后一个原始数据:

iv.getDrawingCache().compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/arun.jpg")));

相同的结果。

I save bitmap as jpg file. The source code is:

imageView = new ImageView(this);
bitmap = Bitmap.createBitmap(d.getWidth() ,d.getHeight() , Bitmap.Config.ARGB_8888);
canvas = new Canvas (bitmap);

iv.setDrawingCacheEnabled(true);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/mrun.jpg")));

I test it on emulator. The file is saved and it has size ~150 Kb. But if I want to open it with any program as MS Paint, I receive the error message. What do I miss? Thanks.
COMMENT: I tried to write instead of the last raw the follow row:

iv.getDrawingCache().compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/arun.jpg")));

Same result.

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

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

发布评论

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

评论(2

如日中天 2025-01-04 08:36:48

我认为 MS Paint 不能与 Alpha 通道一起使用。因此,它无法读取带有 alpha 通道的 jpg。只是一个想法。

尝试使用一些普通的图形编辑器打开。例如,金普。它是免费的。

I think, that MS Paint can't work with Alpha channel. So, it can't read jpg with alpha channel. Just a thought.

try to open by some normal graphic editor. Gimp, for example. It is free.

滥情空心 2025-01-04 08:36:48

最可能的原因:该文件可能未正确写入,即未采用正确的 jpeg 格式。虽然代码看起来没问题。

这有效。

iv.setDrawingCacheEnabled(true);

Bitmap bitmap = iv.getDrawingCache();
iv.buildDrawingCache();

try {
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100,
                    new FileOutputStream(new File("/mnt/sdcard/Temp/mrun.jpg")));
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

The most probable reason: The file might not have been written properly, ie, not in a proper jpeg format. Although the code seems to be fine.

This works.

iv.setDrawingCacheEnabled(true);

Bitmap bitmap = iv.getDrawingCache();
iv.buildDrawingCache();

try {
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100,
                    new FileOutputStream(new File("/mnt/sdcard/Temp/mrun.jpg")));
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文