Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

Saved image is empty

$
0
0

Hi,

I am drawing on a PGraphics and want to save the rendered image to the relevant pictures directory on the external storage. I have set the proper WRITE_EXTERNAL_STORAGE permission. I am using createGraphics() and later save() and everything seems to work fine, but the resulting image is an empty file (0.00 byte).

import android.os.Environment;

try {
  if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
    throw new Exception("External storage is not writable.");
  }

  File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "draw");
  if (!directory.exists() && !directory.mkdirs()) {
    throw new Exception("Directory could not be created.");
  }

  String filename = directory.getAbsolutePath() + File.separator + System.currentTimeMillis() + ".jpg";
  canvas.save(filename);

  println("Picture has been saved to: " + filename);
} catch (Exception e) {
  this.showDialog("Error", e.getMessage());
}

This code would print Picture has been saved to: /storage/emulated/0/Pictures/draw/1483309392341.jpg but the resulting image is an empty file.

Did I miss something?


Viewing all articles
Browse latest Browse all 941

Trending Articles