Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 2395 times)
0 Members and 1 Guest are viewing this topic.
Offline rmdire

Junior Member





« 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
         gf.fillRect(0,0,getWidth(),getHeight());

        // 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,

Cheers

Rmdire
Offline shmoove

Junior Member




Doh!


« 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).

shmoove
Offline rmdire

Junior Member





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

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

Anybody?

cheers

Rmdire
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?
gf.fillRect(0,0,getWidth(),getHeight());

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

Anyway....

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 Member





« 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.

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

JGO Knight


Medals: 12


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.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline rmdire

Junior Member





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

Thanks for your comments

I solved it myself.

Rmdire

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (65 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (36 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!