Questions on Graphics::drawImageAt()


#1

I'm rendering a lot of text from multiple fonts with special positioning, so I've added a system which generates images of the text using the multiple fonts and it works pretty well.  i can render the images using drawImageAt.   however, I noticed when I compared it to drawSingleLineText that a lot of clarity in the image is lost.   Take a look at the following picture: 

that is created with the following code: 

void MainContentComponent::paint(Graphics &g) {
    g.fillAll(Colours::lightblue);
    {
        Image n(Image::ARGB, 300, 200, false );
        Graphics j(n);
        j.setColour(Colours::black);
        j.setFont(textFont->font);
        j.setFont( 36 );
        j.drawSingleLineText("ABCDEFG", 20, 50);
        g.setImageResamplingQuality(Graphics::ResamplingQuality::highResamplingQuality);
        g.drawImageAt(n, 0, 30 );
    }
    g.setColour(Colours::black);
    g.setFont(textFont->font);
    g.setFont( 36 );
    g.drawSingleLineText("ABCDEFG", 20, 50);
}

 

Why is clarity lost when using DrawImageAt compared to drawSingleLineText?   I tried it with "j.setImageResamplingQuality()" before I did any drawing in the section drawing onto Graphics j, but it made no difference.  the text still looked like it was bold compared to the drawSingleLineText() version.  


#2

I found this post: 

http://www.juce.com/forum/topic/rendering-text-image-more-blurry-rending-paint

 

I tried drawing at 2x the image size and using drawImage(), scaling it down.  

that's using the following code:

void MainContentComponent::paint(Graphics &g) {
    g.fillAll(Colours::lightblue);
    {
        float fontSize = 36.f;
        float h = fontSize * 2.f;
        float w = textFont->font.withHeight(h).getStringWidthFloat("ABCDEFG");
        Image n(Image::ARGB, w, h, false );
        Graphics j(n);
        //j.setImageResamplingQuality(Graphics::ResamplingQuality::highResamplingQuality);
        j.setColour(Colours::black);
        j.setFont(textFont->font);
        j.setFont( h );
        j.drawSingleLineText("ABCDEFG", 0, h - 1);

        g.setImageResamplingQuality(Graphics::ResamplingQuality::highResamplingQuality);
        g.drawImage(n, 0, 0, w * 0.5f, h * 0.5f, 0, 0, n.getWidth(), n.getHeight());
    }

    g.setColour(Colours::black);
    g.setFont(textFont->font);
    g.setFont( 36 );
    g.drawSingleLineText("ABCDEFG", 0, 75);
    StringArray s1 = {"A", "B", "C", "D", "E", "F", "G" };
    float w = 0;
    for( auto n : s1 ) {
        g.drawSingleLineText(n, w, 110.f);
        w += textFont->font.withHeight(36).getStringWidthFloat(n);
    }
}