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

2021/6/29

How to reduce image Size?

Me.SatishReddy Me.SatishReddy

2021/6/29

#
Hello, Is anyone there to help me? I am looking to Reduce the Size of my Image in Actor method...Could someone help me with this problem!!
Roshan123 Roshan123

2021/6/29

#
//global
GreenfootImage img=new GreenfootImage("xyz.png");
//Method
img.getImage().scale(50,50);
RcCookie RcCookie

2021/6/29

#
Roshan123 wrote...
//Method
img.getImage().scale(50,50);
The "getImage()" should not be there. It is
img.scale(50, 50);
RcCookie RcCookie

2021/6/29

#
If you want to scale relatively while keeping the aspect ratio:
double scale= 0.5; // for example
img.scale((int)(img.getWidth() * scale), (int)(img.getHeight() * scale));
If you want to scale to a specific width or height but keep the aspect ratio you can use these (untested) methods:
public static void scaleToWidth(GreenfootImage img, int width) {
    img.scale(width, (int)(img.getHeight() * width / (double)img.getWidth()));
}

public static void scaleToHeight(GreenfootImage img, int height) {
    img.scale((int)(img.getWidth() * height / (double)img.getHeight()), height);
}
Gabe1098 Gabe1098

2021/6/29

#
Me.SatishReddy wrote...
Hello, Is anyone there to help me? I am looking to Reduce the Size of my Image in Actor method...Could someone help me with this problem!!
getImage().scale(10,10);
You need to login to post a reply.