You Are Here:

Community: Developer Discussion Boards

#1 Old Transparent Sprites - 2009-04-06, 13:55

Join Date: Apr 2007
Posts: 20
gullet
Offline
Registered User
Hi,

I need to display text to explain details on a map. So I guess that I would go for text-based Sprites, but that will look ugly if I don't use transparent images for the sprites.

My idea is to :
  1. Take the text (mostly short texts) and calculate its dimension from the font and text
  2. Create an image with the width and height of the text
  3. Create an int[] of the size of the image
  4. Fill the int[] with 0xAARRGGBB values
  5. Change the color to the text color
  6. drawString to display the text
  7. Create the sprite from the image

I have googled my brains out for some information regarding text-based sprites, but I haven't found anything. Is it the wrong approach? I'm struggling a bit here, so any help is appreciated.

Thanks in advance.
Reply With Quote

#2 Old Re: Transparent Sprites - 2009-04-06, 15:38

Join Date: Jun 2003
Posts: 4,322
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Essentially, there is no MIDP mechanism for doing what you want, since you cannot create a mutable Image (one you can draw on) where the pixels are transparent.

You have three options.

1. You can do what you want on Nokia devices. Nokia provide an extension API that gives you extra options for creating mutable Image objects. Take a look at the method in the class com.nokia.mid.ui.DirectUtils. Downsides: Nokia and possibly Sony Ericsson only. May not work on some Series 60s.

2. Don't use an Image. Just draw the text where you want it. Downside: drawing text may be slower than drawing an Image.

3. Create a mutable Image with opaque pixels, using Image.createImage(width, height). Draw text on it, in a different colour to the background. Use getRGB() to acquire the pixel data in an int[]. Change all the background colour pixels to transparent, then convert the array back to an Image using Image.createRGBImage(). Downsides: may be slow to do this; pixel arrays can consume a lot of memory (though, your images are probably small); may have unpleasant results on devices with anti-aliased fonts.

Cheers,
Graham.
Reply With Quote

#3 Old Re: Transparent Sprites - 2009-04-07, 08:08

Join Date: Apr 2007
Posts: 20
gullet
Offline
Registered User
Graham,

Thanks for your tips! I went with the third option. It works great, but I have yet to see the performance hit for the "transparency loop".

Thanks!
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make the background of a Custom Canvas Transparent markchua_99 Mobile Java General 4 2008-09-30 03:57
Drawing sprites tjankovic Mobile Java Media (Graphics & Sounds) 4 2003-12-18 17:21
transparent images funworld_0815 Mobile Java General 0 2002-12-09 12:59
Reseting a mutable transparent image keithmarsh Mobile Java General 1 2002-10-10 12:10
Sprites management remarks atomictag Mobile Java General 0 1970-01-01 02:00

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ