从SD卡选择图像,调整图像的大小和背部保存到SD卡 [英] Pick image from sd card, resize the image and save it back to sd card

查看:86
本文介绍了从SD卡选择图像,调整图像的大小和背部保存到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序,其中我需要挑选 SD卡的图像,并显示在图像视图。现在,我希望用户减少/通过点击一个按钮,增加它的宽度,然后将其重新保存到SD卡上。

I am working on an application, in which I need to pick an image from sd card and show it in image view. Now I want the user to decrease/increase its width by clicking a button and then save it back to the sd card.

我也做了影像撷取,并显示它的UI。但无法找到如何调整it.Can请人建议我如何去实现它。

I have done the image picking and showing it on ui. But unable to find how to resize it.Can anyone please suggest me how to achieve it.

推荐答案

就在昨天,我已经做到了这一点。

Just yesterday i have done this

File dir=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Bitmap b= BitmapFactory.decodeFile(PATH_ORIGINAL_IMAGE);
Bitmap out = Bitmap.createScaledBitmap(b, 320, 480, false);

File file = new File(dir, "resize.png");
FileOutputStream fOut;
try {
    fOut = new FileOutputStream(file);
    out.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    fOut.flush();
    fOut.close();
    b.recycle();
    out.recycle();               
} catch (Exception e) {}

另外别忘了回收你的位图:这将节省内存

您还可以得到新创建的文件字符串的路径:的新路径= file.getAbsolutePath();

You can also get path of new created file String: newPath=file.getAbsolutePath();

这篇关于从SD卡选择图像,调整图像的大小和背部保存到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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