从 sd 卡中选取图像,调整图像大小并将其保存回 sd 卡 [英] Pick image from sd card, resize the image and save it back to sd card

查看:22
本文介绍了从 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 上.但无法找到如何调整它的大小.谁能建议我如何实现它.

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) {}

另外不要忘记回收你的位图:它会节省内存.

Also don't forget to recycle your bitmaps: It will save memory.

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

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

这篇关于从 sd 卡中选取图像,调整图像大小并将其保存回 sd 卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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