【问题标题】:How to edit the image correctly from sd card and save it back如何从 sd 卡正确编辑图像并将其保存回来
【发布时间】:2013-11-15 14:21:31
【问题描述】:

我的应用程序访问相机并拍摄照片,然后将其保存回 sdcard
问题是图像相当大,大约 1500X2500 像素和 500kb 大小。
我必须将图像上传到服务器。
所以我想编辑图像,但我想以正确的构图编辑图像,即正确的高度:宽度比,这样图像看起来不会很奇怪

我正在使用的代码:

FileInputStream in = new FileInputStream("/mnt/sdcard/DCIM/1302779969138");
BufferedInputStream buf = new BufferedInputStream(in)                                 
Bitmap bm = BitmapFactory.decodeStream(buf);
File isfile = new File(Environment.getExternalStorageDirectory(),"/DCIM/1302779969138");
FileOutputStream fout = new FileOutputStream(isfile);
Bitmap bitmap = null;

bitmap = Bitmap.createScaledBitmap(bm, 350, 350, true);
bitmap.compress(CompressFormat.JPEG, 20, fout);

使用上面的代码,我可以将图像大小调整为 350 X 350,但我希望仅使用宽度作为参数来缩放它,以便相应地调整高度并且图像比例保持不变

另外还提到我是否应该刷新FileoutputsteaminputStream

【问题讨论】:

    标签: android image-processing bitmap


    【解决方案1】:

    如何在保留其纵横比的情况下缩放图像:

    orig_width = bm.getWidth();
    orig_height = bm.getHeight();
    aspect = orig_width / orig_height;
    new_width = 500;
    new_height = orig_height / aspect;
    

    new_height = 500;
    new_width = orig_width * aspect;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 2011-11-12
      • 2014-03-13
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 2022-07-04
      相关资源
      最近更新 更多