Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Transparency issues  (Read 3767 times)
0 Members and 1 Guest are viewing this topic.
Offline rmdire

Junior Devvie

« Posted 2005-05-17 06:24:11 »

Hi ,

I am trying to build an image in the fly using createImage()
what I want to do is have the background of the image filled with transparency and
then draw my image onto this transparent image, and then use this as a sprite if you like.

(it has to be done this way for the project I am working on)

but for some reason the transparency will not work - i keep getting the image on a non transparent background
- see example code?

spriteImage=Image.createImage(getWidth(), getHeight());
         Graphics gf = spriteImage.getGraphics();
         gf.setColor(0xff0000);                  // seems to fille the image with a red background?Huh

        // should fill with transparent,right?

       // and then draw my sprite on to this image   thus giving a sprite on a transparent background.

Please help, Pretty please,


Offline shmoove

Junior Devvie


« Reply #1 - Posted 2005-05-17 06:29:10 »

createImage(width,height) creates an opaque image, and anything you draw on it will be on an opaque white background. You are drawing a red rectangle on it (ff0000 is red).

Offline rmdire

Junior Devvie

« Reply #2 - Posted 2005-05-17 06:37:40 »

ok - thanks for that - so how can I create
a transparent image?



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RageMatrix

Senior Newbie

Java games rock!

« Reply #3 - Posted 2005-05-18 01:22:32 »

Why are you doing this?

gf.setColor(0xff0000);   // seems to fille the image with a red background Huh?

This does exactly what you're complaining about....fills the image with a red background.


First off, what MIDP version are you using? If you're using MIDP1.0, you can't use transparencies with memory-created images (Image.createImage()). Since you've not provided much information, I'll assume this is the problem.
Offline davidaprice

Junior Devvie

« Reply #4 - Posted 2005-05-19 06:45:18 »

I guess that Rmdire was actually trying to fill the whole rectangle with 'transparent-colour'. But Images created with Image.createImage(width,height) are initially completely white, and even if it was possible to set the drawing colour to transparent, drawing on white with transparent would have no effect, rather like drawing on white paper with a pen that contained no ink.

In MIDP 1.0 there's no way to create a mutable (modifyable) Image with a non-opaque background.

In MIDP 1.0 with Nokia UI API extension (all Nokia MIDP 1.0 phones) you can use the DirectUtils class to create a mutable image whose background is initially any ARGB colour, where A is alpha, i.e. opacity (so 00 is fully transparent, and FF is fully opaque).

In MIDP 2.0 you can use method Image.createRGBImage to create an immutable Image with alpha from an array of ARGB values, which with a little programming can be used to create new transparent sprites.

I'll be asking for MIDP 3.0 to include transparency support similar to that in the Nokia UI API, but there's no guarantee they'll agree.
Offline ameano

Senior Newbie

abstract void

« Reply #5 - Posted 2005-05-19 09:40:25 »

This may be relevant:
Tip for windows gui programmers (e.g. delphi) trying to do J2ME:
Windows developers can use something like an TImage component and then set the transparent colour to any value - this is normally purple for button icons etc, but this does not apply to J2ME images. In J2ME transparency (so far) only has one value: 0x000000 in RGB mode or 0x00000000 in ARGB, etc.
I though I could get away with this (i.e. set the transparent colour value to anything I wanted) when I first started learning J2ME, but obviously not.
Just a random thought which may help prevent future confusion.

rules are there to be broken... same goes for the rules of programming classes in j2me
Offline Abuse

JGO Ninja

Medals: 64

falling into the abyss of reality

« Reply #6 - Posted 2005-05-19 16:45:49 »

Indeed, the graphic shortcomings in j2me are extremely frustrating, and quite ridiculous.

I started having a preliminary look at jsr184 yesterday, and have already found 1 fundamental limitation - which basically results in procedural texturing being hugely inefficient.

Basically, the only functionality that needs adding is Image2D.getGraphics().

However, because this method is not present - you have to :-

1) render to an offscreen image. (necessary operation)
2) getRGB on the offscreen image. (1st unnecessary blit)
3) Convert the packed TYPE_INT_RGB pixels into TYPE_3BYTE_RGB.  (2nd unnecessary *slow* blit)
4) pass this TYPE_3BYTE_RGB into Image2D.set(....) (3rd unnecessary copy)

3 Completely unnecessary memory copies.

If a getGraphics() method haad been included in Image2D, you would be able to bind your Graphics3D context directly to the texure, and eliminate all 3 blits!

All they put in, was a set(x,y,width,height,  TYPE_3BYTE_RGB byte[]);

What purpose does exposing this method serve!
Whatever happened to encapsulation and OO!!

The only conclusion I can make, is that the 'expert' group behind the development of jsr184 arn't realy all that 'expert' afterall.
Offline rmdire

Junior Devvie

« Reply #7 - Posted 2005-05-19 18:51:58 »

Thanks for your comments

I solved it myself.


Pages: [1]
  ignore  |  Print  

EgonOlsen (44 views)
2018-06-10 19:43:48

EgonOlsen (24 views)
2018-06-10 19:43:44

EgonOlsen (46 views)
2018-06-10 19:43:20

DesertCoockie (201 views)
2018-05-13 18:23:11

nelsongames (126 views)
2018-04-24 18:15:36

nelsongames (125 views)
2018-04-24 18:14:32

ivj94 (866 views)
2018-03-24 14:47:39

ivj94 (127 views)
2018-03-24 14:46:31

ivj94 (770 views)
2018-03-24 14:43:53

Solater (142 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!