Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2007, 06:30 PM
Member
 
Join Date: Jul 2007
Posts: 23
marco is on a distinguished road
Help Loading Up Pictures
i need an image format that can have like transparent/ non-visible pixels on it, reason being is to import the sprite of a character onto the template drawn by a background picture also imported
a *.jpg doesnt work coz it solidifies the non-visible colors behind it :/ and a *.gif completely screws up the background template for some reason even if it only has 1 frame
please help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-14-2007, 01:04 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
image format that can have like transparent/ non-visible pixels on it
png works okay for this.
There may be some options depending on what you are trying to do. If loading two images and drawing them one-over-the-other/overlayed doesn't give you what you want you can draw them both into a BufferedImage to use in your app. Here's an example of how you can do it. I made up two images since you didn't sppecify any to work with.
Code:
import java.awt.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import javax.swing.*; public class OverlayImages { private ImageIcon getContent() { return new ImageIcon(getImage()); } private BufferedImage getImage() { BufferedImage bg = getOpaqueImage(); BufferedImage fg = getTranslucentImage(); int w = bg.getWidth(); int h = bg.getHeight(); int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(w, h, type); Graphics2D g2 = image.createGraphics(); g2.drawImage(bg, 0, 0, null); int x = (w - fg.getWidth())/2; int y = (h - fg.getHeight())/2; g2.drawImage(fg, x, y, null); g2.dispose(); return image; } private BufferedImage getOpaqueImage() { int w = 200; int h = 140; int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(w, h, type); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setBackground(Color.orange); g2.clearRect(0,0,w,h); g2.setPaint(Color.green.darker()); g2.draw(new Line2D.Double(w/16.0,h/16.0,w*15/16.0,h*15/16.0-1)); g2.draw(new Line2D.Double(w*15/16.0,h/16.0,w/16.0,h*15/16.0-1)); g2.setPaint(Color.blue); g2.draw(new Rectangle2D.Double(w/16, h/16, w*7/8, h*7/8)); g2.dispose(); return image; } private BufferedImage getTranslucentImage() { int w = 90; int h = 90; int type = BufferedImage.TYPE_INT_ARGB_PRE; BufferedImage image = new BufferedImage(w, h, type); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D e = new Ellipse2D.Double(10,10,w-20,h-20); g2.setPaint(Color.red); g2.fill(e); g2.setPaint(Color.blue); g2.draw(e); g2.dispose(); return image; } public static void main(String[] args) { OverlayImages test = new OverlayImages(); ImageIcon icon = test.getContent(); JOptionPane.showMessageDialog(null, icon, "", JOptionPane.PLAIN_MESSAGE); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-14-2007, 09:43 PM
Member
 
Join Date: Jul 2007
Posts: 23
marco is on a distinguished road
sweet - it all works.. is there anyway to do it with the image.getToolKit syntax for it?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-14-2007, 11:32 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
is there anyway to do it with the image.getToolKit syntax for it?
For making the BufferedImages? The closest thing is the Component createImage method. Check the Method Detail section for this method in the Component api for details about its use (more restricted than BufferedImage way shown above).
Code:
Component c ... // after c is realized and visible int w = ..., h = ... (BufferedImage)c.createImage(w, h);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Funny Pictures Thread(this means a lot of pictures...) joshua Jokes and Funny Things 8 05-08-2008 07:36 AM
Loading Images - Imp Thulasiraman Advanced Java 0 01-28-2008 10:33 AM
Loading An Image Help Please! shaungoater Java 2D 2 01-09-2008 09:14 AM
Help with pictures en Java susan AWT / Swing 1 08-07-2007 05:36 AM
Loading of JSP file failed Heather JavaServer Pages (JSP) and JSTL 2 08-06-2007 02:15 AM


All times are GMT +3. The time now is 04:21 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org