I have a simple applet that lets a user input text, renders it to a PG buffer, and then saves the result (it also loads an image that is used as a background for the text input window). Once the user inputs the text and hits return, it automatically renders it to a TIF and closes the applet.
Quote:import controlP5.*;
ControlP5 controlP5;
PGraphics pg;
PFont font;
public String textValue = "";
PImage backg;
void setup() {
size(500,200);
backg = loadImage("back.png");
pg = createGraphics (2000, 300, JAVA2D);
controlP5 = new ControlP5(this);
controlP5.addTextfield("textValue",100,100,200,20);
controlP5.setColorLabel(0);
font = loadFont("ArialMT-64.vlw");
loop();
}
void draw() {
background(255);
image (backg, 0,0);
float textwidth = pg.textWidth(""+textValue);
pg.beginDraw();
pg.background(255,255,255);
pg.textFont(font,64);
pg.text(""+textValue, 0, 64);
pg.fill(0);
pg.endDraw();
if(textwidth > 0) {
pg.save("text");
exit();
}
}
I want to crop the saved image so that only the text is displayed. I know that this should be fairly easy - I have the text width and height, and its position in the buffer. However, I'm not sure the best way to achieve this (apologies for the code as well - it's probably not the greatest way to go about what I want to do (render inputted text to a cropped single line), but I'm quite new to programming in general). I know you can't do this with save() itself - is there another way to achieve the same thing?
Thanks for your help