We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › save() quality not good enough
Page Index Toggle Pages: 1
save() quality not good enough (Read 585 times)
save() quality not good enough
Dec 8th, 2006, 7:59pm
 
I'm experiencing poor quality when using the save() function to export a JPG.

I am simply loading in a large JPG file, resizing it, putting text over it as a label, and trying to save it out.  It saves it out, but the result is a very dark image.  Is there a way to control save quality or am I doing something wrong?

Also, when using the copy() function and/or the image() function, the images are not actually being rendered.  I'm not using the draw() function at all and I'm wondering if something needs to be done to manually update the pixels on the screen.  updatePixels() does not accomplish this.  

Here is my code:

Code:


import proxml.*;


PImage image1;
PImage image2;
PFont font;
XMLInOut xmlInOut;
XMLElement imagesToResize;
int counter = 1;

void setup() {
size(267, 200);

font = loadFont("Times-Roman-12.vlw");
textFont(font);



xmlInOut = new XMLInOut(this);
try{
xmlInOut.loadElement("/Volumes/My Book/JLWalkerPhotos/resize.xml");
}catch(Exception e){
//if the xml file could not be loaded it has to be created
//xmlEvent(new XMLElement("ellipses"));
println("couldn'topen");
}

noLoop();
}

void xmlEvent(XMLElement element) {
println("yep");
imagesToResize = element;
processImagesToResize();
}


void processImagesToResize() {
imagesToResize.printElementTree(" ");
XMLElement directory;
XMLElement path;
XMLElement caption;

for(int i = 0; i < imagesToResize.countChildren();i++){
directory = imagesToResize.getChild(i);
path = directory.getChild(0);
caption = directory.getChild(1);

processDirectory(path.firstChild().toString(), caption.firstChild().toString());
}

}


void processDirectory(String dirPath, String caption) {
File dir = new File(dirPath);

String[] children = dir.list();
if (children == null) {
// Either dir does not exist or is not a directory
}
else {
for (int i=0; i<children.length; i++) {
// Get filename of file or directory
String filename = children[i];
if(filename.toLowerCase().indexOf(".jpg") > 0) {
if(counter <= 1) {
parseImage(dirPath + "/" + filename, caption);

}
counter++;
println(counter);
}//println(children[i]);
}
}

}


void parseImage(String imgPath, String caption) {

int newWidth = 267;
int newHeight = 200;

println(imgPath + " : " + caption);
image1 = loadImage(imgPath);
//image1.width = 100;
//image1.height = 100;
//image(image1, 0, 0);
copy(image1, 0, 0, image1.width, image1.height, 0, 0, newWidth, newHeight);
fill(#CCCCCC);
noStroke();
rect(0,0,newWidth,20);

// The font must be located in the sketch's
// "data" directory to load successfully

fill(#000000);
textAlign(CENTER);
text(caption, newWidth/2, 15);
//updatePixels();
save("/Users/jordansnyder/Desktop/"+imgPath);
}


Page Index Toggle Pages: 1