Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 8:03 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: AWT Image to Slick Image
PostPosted: Thu Dec 25, 2008 3:01 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
This may sound like a silly question, but how can I create a org.newdawn.slick.Image from a java.awt.Image, which is returned from Tile.getImage()?

Thanks

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 25, 2008 6:52 pm 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
I can't find the Tile class; what package is it in?
Or could you paste a code snippet so we can see whats going on?

I ask because it could be something simple like having the wrong import statement. Even though you probably already checked its nice to eliminate those things before doing some beefy conversion method.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 25, 2008 7:20 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
The Tile.getImage() isn't really the important bit.

I'm basically trying to use the Tiled classes with Slick.
I understand there is a TiledMap class (and private inner classes) within Slick to read .tmx files generated from Tiled, but it's just one class out of the many Tiled ones.

I would find it easier to use the Tiled classes, but these return a java.awt.Image.

So generally, and if possible, how would one go about making a org.newdawn.slick.Image from a java.awt.Image?

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 25, 2008 11:32 pm 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
Ah I see what your doing now. Makes more sense.
Well I don't know of any really good way to do convert them but....
You can convert an awt Image to a buffered Image via

Code:
public BufferedImage convertToBufferedImage(Image img, int imgType){
  BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), imgType);
  Graphics g = buffImg.getGraphics();
  g.drawImage(img, 0, 0, null);
  return buffImg;
}



From there you can use BufferedImageUtil.getTexture(java.lang.String resourceName, java.awt.image.BufferedImage resourceImage) to get a texture then create an empty image and set its texutre

Code:
Texture texture = BufferedImageUtil.getTexture("", bufferedAwtImg);
Image slickImage = new Img(texture.getImageWidth, texture.getImageHeight() );
slickImage.setTexture(texture) ;



That hasn't been tested, I just wrote it up here, but I think that should work. Also I add the disclaimer that this is likely a very poor way of doing it. Hope it helps.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2008 12:44 am 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
Thanks very much mate, but I've taken a long break and typically so, managed to create a solution using the slick-tiled interpreter classes. :]

I'll be on my way until I encounter more hurdles in my game's development. :]

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 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