有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用位图工厂保存图像文件

我遇到了位图工厂的问题。 我有一种方法可以缩小和旋转图像,在图像视图中显示预览,但我想用新的大小保存它。 我只是在使用inputfilestream和outputfilestream,但没有保存它。 有人知道一个清晰的方法将我的位图放入outpufilestream吗? 谢谢 这是我的密码

@Override
protected void onResume() {
    super.onResume();
    File[] fileArray;
    final File root;
    File chemin = Environment.getExternalStorageDirectory();
    String filepath = chemin + "/SmartCollecte/PARC/OUT/" + fichano + "_" + conteneur_s+"_"+cpt+".jpg";


    try {
        decodeFile(filepath);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }}


public void decodeFile(String filePath) {

    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, o);

    // The new size we want to scale to
    final int REQUIRED_SIZE = 1024;

    // Find the correct scale value. It should be the power of 2.
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    // Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    Bitmap b1 = BitmapFactory.decodeFile(filePath, o2);
    Bitmap b = ExifUtils.rotateBitmap(filePath, b1);
    FileOutputStream fos = new FileOutputStream(filePath);
    b.compress(Bitmap.CompressFormat.PNG,100,fos);
    fos.close();
    showImg.setImageBitmap(b);


}

共 (0) 个答案