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

2016/1/30

Mirroring image changes color?

Agent546 Agent546

2016/1/30

#
for some reason whenever i change my image using mirrorHorizonally() the image turns a bright red. whenever i loaded the project (without changing anything) on another computer it worked fine. i then made another project on that computer and it had the same problem. so i took that second project and opened it on the first computer and it worked fine. I have no idea whats wrong.
davmac davmac

2016/1/31

#
We've heard about this but never been able to reproduce it ourselves. It seems to be a bug in either Java or display drivers. However, I think you may have mixed up your computers. You should double-check to make sure you really do the same problem on two different computers but with different projects. If you see the problem in one project, you should definitely see it in all projects on the same machine (however it may affect only some images).
danpost danpost

2016/1/31

#
You could create your own method to mirror an image to avoid using the 'mirrorHorizontally' method:
public static GreenfootImage mirrorHorizontally(GreenfootImage original)
{
    GreenfootImage mirrored = new GreenfootImage(original.getWidth(), original.getHeight());
    for (int y=0; y<original.getHeight(); y++) for (int x=0; x<original.getWidth(); x++)
    {
        Color color = original.getColorAt(x, y);
        int n = original.getWidth()-x-1;
        mirrored.setColorAt(n, y, color);
    }
    return mirrored;
}
Call the method as follows:
image = mirrorHorizonally(image);
You can call the method from any class within your project. Just place the name of the class you placed the method in in front of the method call. For example, if you placed it in a class called MyWorld:
image = MyWorld.mirrorHorizontally(image);
can be used anywhere within your project.
You need to login to post a reply.