This site requires JavaScript, please enable it in your browser!
Greenfoot back
lehrerfreund
lehrerfreund wrote ...

2022/2/19

GreenfootImage: Drawing Strings on JPGs vs. PNGs

lehrerfreund lehrerfreund

2022/2/19

#
When I draw a String on a PNG it looks neat. Drawing it on a PNG always looks pixelated. Is there a workaround having neat Strings on PNGs? When I create a new GreenfootImage with a String it also looks neat and the image has a transparent background (but I am not sure about the format it is stored in).
danpost danpost

2022/2/20

#
lehrerfreund wrote...
Drawing it on a PNG always looks pixelated.
Can you show example code that creates pixelated drawing of string. Show (or explain) how image drawn on is created also, please.
lehrerfreund lehrerfreund

2022/2/22

#
Whilst investigating how I can reproduce the issue I found out what the problem is. In short: It has nothing to do with the image format but with drawing the text repeatedly in the act-method. What works flawlessly:
    public Thing()
    {

    }

    public void addedToWorld(World w)
    {
        GreenfootImage g = this.getImage();
        g.setFont(new Font(13));
        g.drawString("very neat", 11, 11);
        this.setImage(g);
    }
What is generating pixelated images:
    public Thing()
    {

    }
    public void act() 
    {
        GreenfootImage g = this.getImage();
        g.setFont(new Font(13));
        g.drawString("not neat", 11, 11);
        this.setImage(g);
    }  
So my conclusion (I hope I am right): If you draw the String in the act-method it somehow gets pixelated. If you only draw it once (in the example: in the addedToWorld-method) it is neat. Makes sense?
danpost danpost

2022/2/24

#
lehrerfreund wrote...
So my conclusion (I hope I am right): If you draw the String in the act-method it somehow gets pixelated. If you only draw it once (in the example: in the addedToWorld-method) it is neat. Makes sense?
I tested both and did not get any pixelation. My guess is that you are not using a Windows OS. However, obviously, if you only draw the string once, you will get a single image of the text and I do not see how any pixelating could occur with that. If the initial image was just a blank transparent image, another fix might be to use the clear method before re-drawing the string. Although, that would be unnecessarily wasting CPU time (repeatedly working with the image).
lehrerfreund lehrerfreund

2022/2/25

#
danpost, you are right, I am using macOS. Have to try it on Windows. Thanks for you support!
You need to login to post a reply.