Cropping and Saving Portions of an Image
in
Programming Questions
•
1 year ago
Hello All,
I am brand new to Processing, so I fear my initial questions might be obvious ones, but I find myself stuck and hope that someone might be kind enough to offer some advice.
I am analyzing an image and based upon certain criteria, I will want to crop out regions of this image and then save them out to separate files. The problem that I am encountering in the code below is that when I open the initial file (it's a 1360x1024 png file), I can use get() to specify a crop region and it works, but the output (to display as well as to the saved file) is the entire input image with the cropped region overlaid starting at 0, 0.
I guess this is expected...
I have tried leaving out size() and background() and then I simply get a 250x250 image of the standard background color...which I guess is exactly what my code is asking it to do...
So, how would I get just the cropped region to display, and is there a way I could simply save the cropped regions to a file without displaying them?
Any advice would be greatly appreciated!
- void setup()
- {
- size(1360,1024);
- PImage img = loadImage("test1.png");
- background(img);
- PImage myImage = get(500,500,250,250);
- image(myImage,0,0);
- save("ghgh.png");
- }
1