安卓拍照并保存在SD卡之前调整其大小 [英] Android take photo and resize it before saving on sd card

查看:127
本文介绍了安卓拍照并保存在SD卡之前调整其大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的code保存前调整图像大小,但我不能找到它在谷歌任何东西。 你能帮助我吗?

I want my code to resize the image before saving but I can't find anything about it on Google. Could you help me please ?

这是在code(从Android电子文档):

This is the code (from Android doc) :

private void galleryAddPic() {
    Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
    File f = new File(mCurrentPhotoPath);

    picturePathForUpload = mCurrentPhotoPath;

    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}

在那之后,我必须把它上传到服务器。

After that, I have to upload it to a server.

多谢了。

推荐答案

您可以保存位图图像下面code

You can save Bitmap image following code

Bitmap photo = (Bitmap) "your Bitmap image";
photo = Bitmap.createScaledBitmap(photo, 100, 100, false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

File f = new File(Environment.getExternalStorageDirectory()
        + File.separator + "Imagename.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();

这篇关于安卓拍照并保存在SD卡之前调整其大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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