Android:以原始大小将图片保存在SD卡上 [英] Android: Save image on SD card with its original size

查看:148
本文介绍了Android:以原始大小将图片保存在SD卡上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从相机(从设备主屏幕)捕获图像并检查SD卡上的图像大小时,它显示在300-500 Kb之间。

When i capture an image from the camera (from the device home screen) and check the image size on the SD card, it shows between 300-500 Kb.

但是当我使用Camera Intent在我的应用程序中捕获图像并将其保存在SD卡(新文件夹中)时,它显示的图像大小为5-10 Kb。

But when i capture an image in my Application using the Camera Intent, and save it on SD card(in a new folder) it shows image size between 5-10 Kb.

这是我在onActivityResult中拍照后用来将图像保存到SD卡上的代码:

This is the code i am using to save the Image on the SD card after taking the picture in the onActivityResult:

Bitmap bit = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bit.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] ba = bao.toByteArray();
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "My - Images");
File f = new File(imagesFolder, "test.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(ba);
fo.flush();
fo.close();

如何将其保存为原始大小的图像(300-500 Kb)?

how to save it as the original sized image(300-500 Kb)?

,在我将其保存到SD卡之前,有没有办法获得图像大小?

and is there a way to get the image size before i save it on the SD card??

谢谢

推荐答案

您正在使用以下内容压缩收到的位图对象:

You are using the following to compress the bitmap object you receive:

bit.compress(Bitmap.CompressFormat.JPEG, 100, bao);

这就是将位图以压缩格式存储的原因。

That is the reason your bitmap is being stored in a compressed format.

也可以使用 bit.getHeight() bit.getWidth()获得位图的尺寸。您可以使用 bit.getByteCount()来获取位图的实际大小

Also, you can use bit.getHeight() and bit.getWidth() to get the dimensions of your bitmap. You can use bit.getByteCount() to get the actual size of your bitmap

这篇关于Android:以原始大小将图片保存在SD卡上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆