Results 1 to 4 of 4
Thread: Help Loading Up Pictures
- 08-13-2007, 05:30 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 23
- Rep Power
- 0
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 :mad:
please help
- 08-14-2007, 12:04 AM #2
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.
Java 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); } }
- 08-14-2007, 08:43 PM #3
Member
- Join Date
- Jul 2007
- Posts
- 23
- Rep Power
- 0
sweet - it all works.. is there anyway to do it with the image.getToolKit syntax for it?
- 08-14-2007, 10:32 PM #4
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).
Java Code:Component c ... // after c is realized and visible int w = ..., h = ... (BufferedImage)c.createImage(w, h);
Similar Threads
-
The Funny Pictures Thread(this means a lot of pictures...)
By joshua in forum EntertainmentReplies: 22Last Post: 07-25-2012, 09:51 PM -
Loading Images - Imp
By Thulasiraman in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 09:33 AM -
Loading An Image Help Please!
By shaungoater in forum Java 2DReplies: 2Last Post: 01-09-2008, 08:14 AM -
Help with pictures en Java
By susan in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:36 AM -
Loading of JSP file failed
By Heather in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-06-2007, 01:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks