MCPcopy Index your code
hub / github.com/benfry/processing4 / loadImage

Method loadImage

core/src/processing/awt/ShimAWT.java:345–473  ·  view source on GitHub ↗
(PApplet sketch, String filename, Object... args)

Source from the content-addressed store, hash-verified

343
344
345 static public PImage loadImage(PApplet sketch, String filename, Object... args) {
346 String extension = null;
347 if (args != null && args.length > 0) {
348 // the only one that's supported for now
349 extension = (String) args[0];
350 }
351
352 if (extension == null) {
353 String lower = filename.toLowerCase();
354 int dot = filename.lastIndexOf('.');
355 if (dot == -1) {
356 extension = "unknown"; // no extension found
357
358 } else {
359 extension = lower.substring(dot + 1);
360
361 // check for, and strip any parameters on the url, i.e.
362 // filename.jpg?blah=blah&something=that
363 int question = extension.indexOf('?');
364 if (question != -1) {
365 extension = extension.substring(0, question);
366 }
367 }
368 }
369
370 // just in case. them users will try anything!
371 extension = extension.toLowerCase();
372
373 if (extension.equals("tga")) {
374 try {
375 InputStream input = sketch.createInput(filename);
376 if (input == null) return null;
377
378 PImage image = PImage.loadTGA(input);
379 if (image != null) {
380 image.parent = sketch;
381 }
382 return image;
383
384 } catch (IOException e) {
385 e.printStackTrace();
386 return null;
387 }
388 }
389
390 // Disabling for 4.0 beta 5, we're now using ImageIO for TIFF
391 /*
392 if (extension.equals("tif") || extension.equals("tiff")) {
393 InputStream input = sketch.createInput(filename);
394 PImage image = (input == null) ? null : PImage.loadTIFF(input);
395 return image;
396 }
397 */
398
399 // For jpeg, gif, and png, load them using createImage(),
400 // because the javax.imageio code was found to be much slower.
401 // https://download.processing.org/bugzilla/392.html
402 try {

Callers 3

loadImageMethod · 0.95
loadImageMethod · 0.95
loadImageMethod · 0.95

Calls 12

loadTGAMethod · 0.95
loadImageIOMethod · 0.95
joinMethod · 0.95
loadBytesMethod · 0.80
equalsMethod · 0.45
createInputMethod · 0.45
printStackTraceMethod · 0.45
getImageMethod · 0.45
getTypeMethod · 0.45
getColorModelMethod · 0.45
printlnMethod · 0.45
checkAlphaMethod · 0.45

Tested by

no test coverage detected