Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 10:14 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Mar 28, 2010 3:41 pm 
Offline
Regular
User avatar

Joined: Wed Apr 15, 2009 12:51 pm
Posts: 104
Hi kev,

maybe found another bug in ImageIOWriter: saveImage(..) saves the image flipped vertically and ImageOut.write(..) does the same. It seems to be independed to the output format.

Probably I did not understand the things as usual. ;)

I've modified the CopyAreaAlphaTest to be independed to the ImageOutTest.

Code:
package org.newdawn.slick.tests;

import java.io.File;
import java.io.FileOutputStream;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.imageout.ImageIOWriter;

/**
* A test to demonstrate world clipping as opposed to screen clipping
*
* @author kevin
*/
public class CopyAreaAlphaTest extends BasicGame {
   /** The texture to apply over the top */
   private Image textureMap;
   /** The copied image */
   private Image copy;
    private GameContainer container;
   
   /**
    * Create a new tester for the clip plane based clipping
    */
   public CopyAreaAlphaTest() {
      super("CopyArea Alpha Test");
   }
   
   /**
    * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
    */
   public void init(GameContainer container) throws SlickException {
      textureMap = new Image("testdata/grass.png");
      container.getGraphics().setBackground(Color.black);
      copy = new Image(100,100);
      
      this.container = container;
   }

   /**
    * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
    */
   public void update(GameContainer container, int delta)
         throws SlickException {
   }

   /**
    * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
    */
   public void render(GameContainer container, Graphics g)
         throws SlickException {
      g.clearAlphaMap();
      g.setDrawMode(Graphics.MODE_NORMAL);
      g.setColor(Color.white);
      g.fillOval(100,100,150,150);
      textureMap.draw(10,50);
      
      g.copyArea(copy, 100,100);
      g.setColor(Color.red);
      g.fillRect(300,100,200,200);
      copy.draw(350,150);
   }

   /**
    * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
    */
   public void keyPressed(int key, char c) {
        if (key == Input.KEY_F5) {
            try {
                Image image = new Image(container.getWidth(), container.getHeight());
                container.getGraphics().copyArea(image, 0, 0);
               
                // Bug in ImageIOWriter causes the image to be flipped vertically
                //image = image.getFlippedCopy(false, true);

                File file = new File(System.getProperty("user.home") + "/TestScreenshot.jpg");
                FileOutputStream stream = new FileOutputStream(file);
               
                ImageIOWriter writer = new ImageIOWriter();
                writer.saveImage(image, "jpg", stream, false);
            } catch (Exception e) {
                System.err.println("Could not save screenshot: "+e.getMessage());
            }
        }
   }
   
   /**
    * Entry point to our test
    *
    * @param argv The arguments to pass into the test
    */
   public static void main(String[] argv) {
      try {
         AppGameContainer container = new AppGameContainer(new CopyAreaAlphaTest());
         container.setDisplayMode(800,600,false);
         container.start();
      } catch (SlickException e) {
         e.printStackTrace();
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2010 8:30 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Fixed in SVN.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group