[java] CRIMENY!
There has to be a way to use transparent images (gif/png) in applets! (Doesn''t there?).
I''ve spent most of the day exporting images with transparent backgrounds from photoshop to .gifs and .pngs and trying to use them in my applet hoping that transparency would be preserved.
alas, it is not.
Am I going to have to write my own gif/png blitter to get the results I so badly crave!
please advise...
thanks
I had never problems using transparent gifs in java. Have you tested if your exported gifs are really transparent? Maybe it is an export problem.
if you''re using win32, mspaint will do the job easily.
_______________________
http://mill.3dfxsweden.net
_______________________
http://mill.3dfxsweden.net
Yeah I just tested that the images are actually being exported correctly. Maybe it has to do with the way they are being copied?
I'm glad you guys chimed in saying it works. It gives me some hope =)
Could someone post a small example that works?
Mill-o: You say it works with MSPAINT? I thought MSPAINT only worked with .BMPs? So does it support transparent bitmaps as well? That'd be nice =)
How does it know which color is the transparent one?
Thanks!
[edited by - Violenza on April 17, 2002 10:38:50 AM]
I'm glad you guys chimed in saying it works. It gives me some hope =)
Could someone post a small example that works?
Mill-o: You say it works with MSPAINT? I thought MSPAINT only worked with .BMPs? So does it support transparent bitmaps as well? That'd be nice =)
How does it know which color is the transparent one?
Thanks!
[edited by - Violenza on April 17, 2002 10:38:50 AM]
it depends on how you are creating your images (atleast _I_ can''t get trans gifs to work using some particular methods for creating images). the methos below works though:
_______________________
http://mill.3dfxsweden.net
public Image loadImage(String fileName) { Image loadedImage = null; Image returnImage = null; MediaTracker tracker = new MediaTracker(new Container()); try { InputStream in = this.getClass().getResourceAsStream(fileName); ByteArrayOutputStream imageByteStream = new ByteArrayOutputStream(); byte[] currentBytes = new byte[2048]; int bytesRead = 0; while ((bytesRead = in.read(currentBytes)) != -1) imageByteStream.write(currentBytes,0,bytesRead); loadedImage = Toolkit.getDefaultToolkit().createImage(imageByteStream.toByteArray()); tracker.addImage(loadedImage, 0); } catch (Exception e) {} try {tracker.waitForAll();} catch (InterruptedException e) {} returnImage = new BufferedImage(loadedImage.getWidth(null),loadedImage.getHeight(null),BufferedImage.TYPE_INT_ARGB); returnImage.getGraphics().drawImage(loadedImage,0,0,null); return returnImage; }
_______________________
http://mill.3dfxsweden.net
forgot about mspaint..
dunno about older versions, but version 5 has support for it.
1. open a gif
2. Image menu | Attributes
3. and there the Transparency section is!
oh another note, the code i just pasted could probably be done easier, but this is what i use in my image toolkit class.
_______________________
http://mill.3dfxsweden.net
dunno about older versions, but version 5 has support for it.
1. open a gif
2. Image menu | Attributes
3. and there the Transparency section is!
oh another note, the code i just pasted could probably be done easier, but this is what i use in my image toolkit class.
_______________________
http://mill.3dfxsweden.net
Thanks for the code post mill-o.
After spending a lot of time on this issue I can say I am more confused than before. Here are a couple excerpts from a document on understanding AWT image types (http://www.javagaming.org/Documents/Understanding_AWT_Image_Types/understanding_awt_image_types.html)
then you also see
These to me are conflicting. One says hardware accelerated images (VolatileImages) can''t have transparency, but the other part says 2 ways to do it.
Regardless, when using Volatile images it doesn''t work for me. I don''t know if it''s from bad code or because it''s not possible.
After spending a lot of time on this issue I can say I am more confused than before. Here are a couple excerpts from a document on understanding AWT image types (http://www.javagaming.org/Documents/Understanding_AWT_Image_Types/understanding_awt_image_types.html)
quote:
"VolatileImages as BLT destination (or source) currently do not support transparency when doing an API level BLT. If you attempt to BLT a BufferedImage with transparent pixels into a VolatileImage to gain hardware acceleration you will lose the transparency information"
then you also see
quote:
"If you want to create sprites or other images that contain transparent pixels and have hardware accelerated graphics support, you have two choices:
(1)Use Toolkit.getImage() to load an image from a file.
(2) GraphicsConfiguration.createCompatibleImage(int width, int height, int transparency) with transparency set to Transparency.BITMASK"
These to me are conflicting. One says hardware accelerated images (VolatileImages) can''t have transparency, but the other part says 2 ways to do it.
Regardless, when using Volatile images it doesn''t work for me. I don''t know if it''s from bad code or because it''s not possible.
Volatile images do not have transparancy. You can however draw to them with a image that does and still get hardware acceleration. Use volatiles for backgrounds or other images that don''t need an alpha. Use one of the other two methods for images that do. Blending is not accelerated in any fasion, unfortunately, but hopefully that will change soon.
The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran
Opere Citato
The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran
Opere Citato
currently VolatileImages only support 1-bit transparency (as in no support for alpha blending, only one colour)
i thougth that said in the article though
_______________________
http://mill.3dfxsweden.net
i thougth that said in the article though
_______________________
http://mill.3dfxsweden.net
Ok.. I''ll rephrase my scenario a bit since I''m still a little confused based on the posts above.
I''m not trying to do any blending of any sort. I simply have images (.gif) that have transparent color key.
I would like to blit to an offscreen surface (a VolatileImage). But it seems that when you blit to
Once I blit a .gif with transparencies to the offscreen image it appears to lose the transparency info somehow. Because when I blit form the offscreen surface to the main surface it no longer has transparent sections.
Is this possible to achieve using Volatile images?
Thanks!
I''m not trying to do any blending of any sort. I simply have images (.gif) that have transparent color key.
I would like to blit to an offscreen surface (a VolatileImage). But it seems that when you blit to
Once I blit a .gif with transparencies to the offscreen image it appears to lose the transparency info somehow. Because when I blit form the offscreen surface to the main surface it no longer has transparent sections.
Is this possible to achieve using Volatile images?
Thanks!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement