IT Community - Software Programming, Web Development and Technical Support

Any simple step or sample code for transparency mobile..?

This is a discussion on Any simple step or sample code for transparency mobile..? within the Mobile Software Development forums, part of the Software Development category; Hi..I am getting really frustrated with DirectGraphics. Is there anywhere that I can find a simple step by step ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Mobile Software Development

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 06:26 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Default Any simple step or sample code for transparency mobile..?

Hi..I am getting really frustrated with DirectGraphics. Is there anywhere that I can find a simple step by step tutorial or code sample to show how transparency on a mobile might be implemented?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 06:43 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Any simple step or sample code for transparency mobile..?

Hi... don't worry... you can try this...
Firstly, the native transparent file format in MIDP is the .png file. On the Series 40 (7210, 6610, 6100), a .png file allows not only entirely transparent pixels, but also translucent ones. Unfortunately, with the Series 60 (3650, 7650) as far as I can see, only transparent pixels can be used - which is the main thing.

Save .png file with a transparency mask. To do this in paint shop pro:

1. File->New Image.
2. Draw Image.
3. Masks->New->Show All.
4. Masks->View Mask
5. Masks->Edit
6. The colour palette will change to grey scale - select absolute black (0,0,0)
7. Paint over the pixels in your image that you wish to be invisible.
8. Masks->Save to Alpha Channel.
9. Hit OK twice.
10. Save the image.

Followings are to use the newly created image in your application

1. Make sure you have the path with the graphics files mounted (right click on
File Systems->Mount->Local Directory)

2. Include the .png file in your jar file - In Sun One, right click the Midlet Suite Icon and select 'Edit Suite', then the tab 'Jar Contents'. Browse on the left side to the newly mounted directory, and select the png file. Click 'Add'. Click 'OK'.

3. Create a class variable: [Image MadCrazyDudeImage=null;]

4. In your Class constructor (or wherever appropriate), create the image from the .png file.
[MadCrazyDudeImage= Image.createImage("/MadCrazyDude.png");] It is vital that the case of the name is the correct case, and that you preceed the filename with the forward slash.

5. Create a DirectGraphics object in your paint routine, and initialise it: [DirectGraphics dg;
dg=DirectUtils.getDirectGraphics(graphics);]

6. Draw the image to the canvas. [dg.drawImage(MadCrazyDudeImage, 0, 0, Graphics.TOP | Graphics.LEFT, 0);]

If this doesn't work, it may be that you are trying to read the graphics out of a graphics strip first (this is the part that threw me when porting my first Series 40 to a Series 60 phone). To do this, you cannot use a Graphics object alone to create your individual images.
They have to be passed through a DirectGraphics object for the transparency to be maintained. I include the code that I use below:

In the class global area:

Image imReceptors=null;
Image Receptors[]=new Image[12];

imReceptors=Image.createImage("/S60receptors.png");
for (int i=0; i<12; i++)
{
Receptors[i]=DirectUtils.createImage(21, 20, 0x00000000);
Graphics g = Receptors[i].getGraphics();
DirectGraphics dgtemp=DirectUtils.getDirectGraphics(g);
dgtemp.drawImage(imReceptors, -21*i, 0, Graphics.TOP | Graphics.LEFT, 0);
}
imReceptors=null;

It's best to put a try...catch block around your graphics creation code to make sure that there isn't a problem there (i usually just add a System.out.println("Graphics Error here") type of statement to the catch block). If using Sun One, you may be getting frustrated because Sun One is expecting the graphics to be located a sub folder up from where you would expect it to look for them. Try placing the images into the parent directory of your app project if Sun One is struggling to find them in the main app directory. But I know there is a bug or something with the transparency on s60! also in the emulator it doesn’t work - dont no why and i got no solution for that you cant make a transparent image with:

MyImage = DirectUtils.createImage(16, 16, 0x00000000);

With this code you got an image with a black background it only works on s40 and s30 phones

I hope this helps.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Step By Step Procedure to create project? poornima ASP and ASP.NET Programming 3 04-07-2008 02:45 AM
Need a step-by-step walkthrough Ameno Networking & Internet Connectivity 0 01-17-2008 06:34 AM
Is there any sample code for sending a text file from the phone to the PC via... mobilegeek Mobile Software Development 4 09-11-2007 04:12 AM
Write sample code for pagination using java script itbarota HTML, CSS and Javascript Coding Techniques 1 09-11-2007 12:00 AM
Can you show a simple code showing file dependency in cache in asp.net ? oxygen ASP and ASP.NET Programming 1 07-26-2007 04:08 AM


All times are GMT -7. The time now is 11:37 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0