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

2018/6/10

GreenfootImage scaler ruins the image quality!

JOELwindows7 JOELwindows7

2018/6/10

#
I am not sure what type of this asking it should be. But most importantly, it is about Greenfoot system that appears to be a trouble. I am scaling an image in an actor.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class BoomImage here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BoomImage extends ExplosionImage
{
    private boolean existed = false;
    private int Sequence = 0;
    private int [] DynaSize = new int[] {0,0};
    private int DynaX = 0;
    private int DynaY = 0;
    private int [] Ukuran = new int[]{getImage().getWidth(), getImage().getHeight()};
    private int nonDeltaTimeKey = 100;
    private GreenfootImage baseImg = new GreenfootImage("BoomImage.png");
    private GreenfootImage imaging = new GreenfootImage(baseImg);
    public BoomImage(){
        DynaSize[0] = 1;
        DynaSize[1] = 1;
        imaging.scale(Ukuran[0], Ukuran[1]);
        setImage(imaging);
        //existed = true;
    }
    public void addedToWorld(World world){
        existed = true;
        Sequence = 0;
        
    }
    /**
     * Act - do whatever the ExplosionImage wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        //DynaSize[0] += 10;
        //DynaSize[1] += 10;
        //imaging.scale(DynaSize[0], DynaSize[1]);
        //setImage(imaging);
        if(existed == true){
            
            if(Sequence == 0){
                if(DynaSize[0] < Ukuran[0] || DynaSize[1] < Ukuran[1]){
                    DynaSize[0] += 10; 
                    DynaSize[1] += 10;
                    
                } else if(DynaSize[0] >= Ukuran[0] || DynaSize[1] > Ukuran[1]){
                    Sequence = 1;
                }
            } else if(Sequence == 1){
                if(DynaSize[0] > 2 || DynaSize[1] > 2){
                    DynaSize[0] -= 10; 
                    DynaSize[1] -= 10;
                    
                } else if(DynaSize[0] <= 2 || DynaSize[1] <= 2){
                        
                    imaging.setTransparency(0);
                    Sequence = 2;
                }
            }
            imaging.scale(DynaSize[0], DynaSize[1]);
            setImage(imaging);
        }
    }    
}
this actor does expand the size of the image, then shrink again. Now, I have added the actor to the World.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class testResult2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class testResult2 extends testAreas
{

    /**
     * Constructor for objects of class testResult2.
     * 
     */
    public testResult2()
    {
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        levelNumber levelnumber = new levelNumber(12, "Windowsl");
        addObject(levelnumber,getWidth()/2,12);
        DuarImage duarimage = new DuarImage();
        addObject(duarimage,255,202);
        BoomImage boomimage = new BoomImage();
        addObject(boomimage,446,202);
        
    }
}
there. The problem is: After the image being reffered shrunk, the quality ruins! Before Act: After Act: image size shrinking: Sorry for large images. Basically, I simply scale and update the set image with the new setting reffered. I must have used the scaler wrongly. If you have any solution to make the image does not broke with scaling, feel free and thanks for your help.
danpost danpost

2018/6/11

#
JOELwindows7 wrote...
I am not sure what type of this asking it should be. But most importantly, it is about Greenfoot system that appears to be a trouble.
Greenfoot is fine, I assure you (as least as far as what you are trying to do).
I am scaling an image in an actor. << Code Omitted >> this actor does expand the size of the image, then shrink again. << Code Omitted >> The problem is: after the image being reffered shrunk, the quality ruins! << Images Omitted >> Sorry for large images. Basically, I simply scale and update the set image with the new setting reffered. I must have used the scaler wrongly. If you have any solution to make the image does not broke with scaling, feel free and thanks for your help.
Replace lines 64 and 65 with the following two lines:
setImage(new GreenfootImage(imaging));
getImage.scale(DynaSize[0], DynaSize[1]);
Repeated scaling of the same image will cause pixelation or degradation of the image. So, make a new image of what you are scaling each time and you will be okay. Do similar for lines 23 and 24 as well.
JOELwindows7 JOELwindows7

2018/6/11

#
danpost wrote...
JOELwindows7 wrote...
I am not sure what type of this asking it should be. But most importantly, it is about Greenfoot system that appears to be a trouble.
Greenfoot is fine, I assure you (as least as far as what you are trying to do).
I am scaling an image in an actor. << Code Omitted >> this actor does expand the size of the image, then shrink again. << Code Omitted >> The problem is: after the image being reffered shrunk, the quality ruins! << Images Omitted >> Sorry for large images. Basically, I simply scale and update the set image with the new setting reffered. I must have used the scaler wrongly. If you have any solution to make the image does not broke with scaling, feel free and thanks for your help.
Replace lines 64 and 65 with the following two lines:
setImage(new GreenfootImage(imaging));
getImage.scale(DynaSize[0], DynaSize[1]);
Repeated scaling of the same image will cause pixelation or degradation of the image. So, make a new image of what you are scaling each time and you will be okay. Do similar for lines 23 and 24 as well.
That's what do I meant! I should load the new image everytime, from the disk, not from this Greenfoot situation.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class BoomImage here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class BoomImage extends ExplosionImage
{
    private boolean existed = false;
    private int Sequence = 0;
    private int [] DynaSize = new int[] {0,0};
    private int DynaX = 0;
    private int DynaY = 0;
    private int [] Ukuran = new int[]{getImage().getWidth(), getImage().getHeight()};
    private int nonDeltaTimeKey = 100;
    private GreenfootImage baseImg = new GreenfootImage("BoomImage.png");
    private GreenfootImage imaging = new GreenfootImage(baseImg);
    public BoomImage(){
        DynaSize[0] = 1;
        DynaSize[1] = 1;
        //imaging.scale(Ukuran[0], Ukuran[1]);
        //setImage(imaging);
        setImage(new GreenfootImage(imaging));
        getImage().scale(Ukuran[0], Ukuran[1]);
        //existed = true;
    }
    public void addedToWorld(World world){
        existed = true;
        Sequence = 0;
        
    }
    /**
     * Act - do whatever the ExplosionImage wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        //DynaSize[0] += 10;
        //DynaSize[1] += 10;
        //imaging.scale(DynaSize[0], DynaSize[1]);
        //setImage(imaging);
        if(existed == true){
            
            if(Sequence == 0){
                if(DynaSize[0] < Ukuran[0] || DynaSize[1] < Ukuran[1]){
                    DynaSize[0] += 10; 
                    DynaSize[1] += 10;
                    
                } else if(DynaSize[0] >= Ukuran[0] || DynaSize[1] > Ukuran[1]){
                    Sequence = 1;
                }
            } else if(Sequence == 1){
                if(DynaSize[0] > 2 || DynaSize[1] > 2){
                    DynaSize[0] -= 10; 
                    DynaSize[1] -= 10;
                    
                } else if(DynaSize[0] <= 2 || DynaSize[1] <= 2){
                        
                    imaging.setTransparency(0);
                    Sequence = 2;
                }
            }
            //imaging.scale(DynaSize[0], DynaSize[1]);
            //setImage(imaging);
            setImage(new GreenfootImage(imaging));
            getImage().scale(DynaSize[0], DynaSize[1]);
        }
    }    
}
And now, no more downgrade quality. Thx man! Please set this thread as solved. P.S: remember to getImage(); The parenthesis! ()
You need to login to post a reply.