MCPcopy Index your code
hub / github.com/processing/processing / save

Method save

core/src/processing/core/PImage.java:3374–3437  ·  view source on GitHub ↗

( begin auto-generated from PImage_save.xml ) Saves the image into a file. Append a file extension to the name of the file, to indicate the file format to be used: either TIFF (.tif), TARGA (.tga), JPEG (.jpg), or PNG (.png). If no extension is included in the filename, the image will save in TIFF

(String filename)

Source from the content-addressed store, hash-verified

3372 * @param filename a sequence of letters and numbers
3373 */
3374 public boolean save(String filename) { // ignore
3375 boolean success = false;
3376
3377 if (parent != null) {
3378 // use savePath(), so that the intermediate directories are created
3379 filename = parent.savePath(filename);
3380
3381 } else {
3382 File file = new File(filename);
3383 if (file.isAbsolute()) {
3384 // make sure that the intermediate folders have been created
3385 PApplet.createPath(file);
3386 } else {
3387 String msg =
3388 "PImage.save() requires an absolute path. " +
3389 "Use createImage(), or pass savePath() to save().";
3390 PGraphics.showException(msg);
3391 }
3392 }
3393
3394 // Make sure the pixel data is ready to go
3395 loadPixels();
3396
3397 try {
3398 OutputStream os = null;
3399
3400 if (saveImageFormats == null) {
3401 saveImageFormats = javax.imageio.ImageIO.getWriterFormatNames();
3402 }
3403 if (saveImageFormats != null) {
3404 for (int i = 0; i < saveImageFormats.length; i++) {
3405 if (filename.endsWith("." + saveImageFormats[i])) {
3406 if (!saveImageIO(filename)) {
3407 System.err.println("Error while saving image.");
3408 return false;
3409 }
3410 return true;
3411 }
3412 }
3413 }
3414
3415 if (filename.toLowerCase().endsWith(".tga")) {
3416 os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
3417 success = saveTGA(os); //, pixels, width, height, format);
3418
3419 } else {
3420 if (!filename.toLowerCase().endsWith(".tif") &&
3421 !filename.toLowerCase().endsWith(".tiff")) {
3422 // if no .tif extension, add it..
3423 filename += ".tif";
3424 }
3425 os = new BufferedOutputStream(new FileOutputStream(filename), 32768);
3426 success = saveTIFF(os); //, pixels, width, height);
3427 }
3428 os.flush();
3429 os.close();
3430
3431 } catch (IOException e) {

Callers

nothing calls this directly

Calls 11

createPathMethod · 0.95
showExceptionMethod · 0.95
loadPixelsMethod · 0.95
saveImageIOMethod · 0.95
saveTGAMethod · 0.95
saveTIFFMethod · 0.95
savePathMethod · 0.80
printlnMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
printStackTraceMethod · 0.45

Tested by

no test coverage detected