2012-09-19 16 views
5

Ho il seguente codice che è adattato da un esempio online per la rotazione del testo. Il codice funziona bene in quanto ruota il testo all'angolo corretto, ma vorrei sapere se c'è un modo per migliorare la precisione e la nitidezza del testo ruotato. Sul mio display sembra che il testo ruotato sia "scalato" anziché liscio.Miglioramento della visualizzazione del testo ruotato

PFont f; 
String message = "abcdefghijklmnopqrstuvwxyz"; 
float theta, x; 

void setup() { 
    size(800, 200); 
    f = createFont("Arial",20,true); 
} 

void draw() { 
// background(255); 
    fill(0); 
    textFont(f); // Set the font 
    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 
    textAlign(LEFT);    
    text(message,0,0);    
    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

Ho modificato l'esempio per aiutare a visualizzare la differenza. Nel nuovo codice ho cambiato il testo in una stringa di trattini bassi e disegnato anche una linea di riferimento in rosso. Se funziona lo stesso sulla tua macchina dovresti vedere uno scaglionamento nella linea nera creata dai trattini bassi.

String message = "________"; 
float theta, x; 
PFont f; 

void setup() { 
    size(800, 200); 
    f = loadFont("ArialMT-20.vlw"); 
    smooth(); 
} 

void draw() { 
    fill(0); 
    textFont(f); // Set the font 

    translate(x,height/2); // Translate to the center 
    rotate(theta);    // Rotate by theta 

    text(message,0,0); 

    stroke(255,0,0); 
    strokeWeight(2); 
    line(0,0,textWidth(message),0); 

    theta += 0.1;    // Increase rotation 
    x += textWidth(message); 
    if (x>800){noLoop(); } 
} 

Per me ha pronunciato la seguente uscita, ma so che questo sarà diverso se eseguito su un Mac:

enter image description here

+1

Per un aiuto migliore, pubblicare un [SSCCE] (http://sscce.org/). –

+1

Forse stai cercando anti-alisasing? http://www.universalwebservices.net/web-programming-resources/java/anti-aliasing-creating-anti-alias-text-in-java – dbalakirev

+0

Avrei dovuto dire che questo è il codice Processing.org quindi è possibile copiare e incollare nell'IDE ed eseguire. Hai ragione, sto cercando il testo anti-alias e come capisco dovrebbe essere. Quando creo il font, l'opzione 'true' seleziona l'anti-aliasing. – user1682655

risposta

0

Un modo per farlo è quello di tracciare il testo (non ruotato) in una BufferedImage, e poi ruotare l'immagine. Qualcosa del genere:

BufferedImage buff = getGraphicsConfiguration().createCompatibleImage(textWidth, textHeight); //create an image with the dimensions of the text 
Graphics2D g2d = buff.createGraphics(); 
g2d.drawString(yourText); //draw the text without transformations 
g2d.dispose(); 

//apply the rotation transform to g, the Graphics from your component 
g.drawImage(buff, textPosX, textPosY, null); //there you go 
Problemi correlati