I just got
PhiLho
's
ignotus 's
code from this
post
to isolate and test a behavior i was getting in a more complex sketch.
I inserted two lines, to print window size against loaded image size, they are not equal in height (usually
in first image loaded they equal but not in next loaded). Why is that?
I am willing to use default pixels array with loaded image, but the array is not the correct size cause of this error...
any help?
thanks
v.k.
ps: Also I inserted OPENGL at size call cause i intend to use it in my sketch, but I tested and this does not change the problem.
-
- /*
- * A simple application to show how to change the window size to fit an image.
- * No provision is made for images that are bigger than the screen dimensions.
- * That would be a good exercise.
- * Makes use of "undocumented" features, found in the Processing JavaDocs but
- * not in the online help pages: frame.setResizable and frame.setSize.
- * Click in the window to load a new image.
- */
-
- //// MODIFIED CODE!!! As pointed below
-
- PImage img;
-
- void setup() {
- String path = selectInput("Select an image file to display...");
- if (null != path) {
- img = loadImage(path);
- size(img.width, img.height);
- }
- else {
- // ADDED OPENGL render
- size(320, 240, OPENGL);
- }
- // permit the display window to be resized
- frame.setResizable(true);
- }
-
- void draw() {
- if (mousePressed == true) {
- pickImage();
- }
- if (null != img) image(img, 0, 0, width, height);
- /// inserted code
- println("img.width = "+img.width+" x img.height = "+img.height);
- println("width = "+width+" x height = "+height);
- /// end of inserted code
- }
-
-
-
- void pickImage() {
- String path = selectInput("Select an image file to display...");
- if (null == path) {
- println("no file selected");
- }
- else {
- img = loadImage(path);
- frame.setSize(img.width, img.height);
- }
- }
-
1