Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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  
  .png image bug  (Read 1774 times)
0 Members and 1 Guest are viewing this topic.
Offline xdebugx

Senior Newbie




Down with the classes, equal methods for all.


« Posted 2005-04-08 06:55:12 »

I'm using Image.getRGB and Image.createRGBImage to resize images in midp2.0.  It works fine on the emulator.  But when I run the game on my palm tungsten E, with the ibm j9 kvm, I get a wierd error.  When the image is painted it shows a red square the size of the image.  I found that if I turn double-buffering off it paints the image correctly.  Also I found that the image is painted correctly with double buffering on, when I save the original image as a 24 bit rgb image.  When I save the image as a 8bit indexed color image, it works on the emulator, but not on the device.  Any ideas if this is a problem on other devices or how I can save the image as 8bit and still get it to display properly?

Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #1 - Posted 2005-04-08 08:51:13 »

Have you tested on Nokia series 60 at all?  There is a major bug with regards to image creation with the createRGBImage() method in that you should be unable to an image of size larger than 4095 ints (tha array that contains the image data).  Please let me know if you have not experienced this problem.

Cheers,

ribot

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline xdebugx

Senior Newbie




Down with the classes, equal methods for all.


« Reply #2 - Posted 2005-04-09 01:14:52 »

I haven't been able to test on any nokia series 60 devices.  I have tried it with a series 60 emulator but I get the error "no such method getRGB"  I guessing the series 60 emulator I have is not midp 2.0.   Encase your wondering I have found a work around for the 4095 int limit.  The code is below, basically I resize strips of the image that are less than 4095 int big, then put them back together in one image.   It's takes more runtime memory, but doesnt use more than 4095 ints at one time.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
try {
 boardImg=Image.createImage ("/images/board.png");
 
 Image pieceImage,newImage;
 newImage=Image.createImage(boardWidth,boardHeight);
 Graphics newImageG=newImage.getGraphics();
 //board width =180, board height = 160
int rgbdata[] = new int [180*(160/10)];
 for (p=0;p<10;p++) {
 boardImg.getRGB (rgbdata,0,180,0,p*(16),180,16);
 pieceImage=Image.createRGBImage (rgbdata,180,16,false);
 pieceImage=resize (pieceImage,boardWidth,(boardHeight/10));
 newImageG.drawImage (pieceImage,0,p*(boardHeight/10),0);
 pieceImage=null;
 System.gc();
 }
 boardImg=newImage;
 newImage=null;

 System.gc();
//boardImg=resize (boardImg,boardWidth,boardHeight);

      } catch (Exception e) {System.out.println ("Error loading images: "+e);}
 }


The more strips you create the more likely the image will be off somewhat.  If your interested in my resize code, I found it in the forums from a member named Yu You, I had written a similar resize code before but Yu You's was much faster than mine.  It is below.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
        public static Image resize(Image originalImage, int width, int height) { 
              //if (height <= 0 || width <= 0)
             //throw new Exception("ERROR_INVALID_ARGUMENT");
             if (originalImage == null)
                    return Image.createImage(height, width);
              int orig_h = originalImage.getHeight();
              int orig_w = originalImage.getWidth();
              if (orig_w == width && orig_h == height)
                    return originalImage;
              int[] orig = new int[orig_h * orig_w];
              originalImage.getRGB(orig, 0, orig_w, 0, 0, orig_w, orig_h);
              int index;
              int[] newbuffer = new int[height * width];
              int loc, oldloc = 0;
              //long before = System.currentTimeMillis();
             for (int i = 0; i < height; i++) {
                    for (int j = 0; j < width; j++) {
                          loc = i * width + j;
                          index = (int) (i * orig_h / height) * orig_w
                                      + (int) (j * orig_w / width);
                          //System.arraycopy(orig,index,newbuffer,loc,1);
                         newbuffer[loc] = orig[index];
                    }
              }
              //System.out.println("time:"+(System.currentTimeMillis()-before));
            Image newImage = Image.createRGBImage(newbuffer, width, height, false);
              orig = null;
              newbuffer = null;
              System.gc(); //  
             return newImage;
        }

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

Senior Newbie




Down with the classes, equal methods for all.


« Reply #3 - Posted 2005-04-09 03:08:03 »

The solution I've finnally come up with is to not use getRgb and createRGBIMage at all.  Since I'm not worried about tranparent pixels in this game, I instead set a clip region in the image im resizing and paint the old image.  Its very slow is the only probelm.  I modified Yu You's code to use image painting instead of getRGB and now it works on my device and is midp 1.0 compatible.  Only problem is its slow and it doesnt work for transparent images because of the createImage (width,height);  The code is listed below:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public static Image resize2(Image originalImage, int width, int height) { 
                          //if (height <= 0 || width <= 0)
                         //throw new Exception("ERROR_INVALID_ARGUMENT");
                         if (originalImage == null)
                                return Image.createImage(height, width);
                          int orig_h = originalImage.getHeight();
                          int orig_w = originalImage.getWidth();
                          if (orig_w == width && orig_h == height)
                                return originalImage;
                          int index;
                          int loc, oldloc = 0;
                          Image newImage = Image.createImage (width,height);
                          Graphics newImageG=newImage.getGraphics();
                          //long before = System.currentTimeMillis();
                         for (int i = 0; i < height; i++) {
                                for (int j = 0; j < width; j++) {
                                      //System.arraycopy(orig,index,newbuffer,loc,1);
                                   //  newbuffer[loc] = orig[index];
                                     newImageG.setClip (j,i,1,1);
                                      newImageG.drawImage (originalImage,j-(int) (j*orig_w/width),i-(int) (i*orig_h/height),0);
                                }
                          }
                          //System.out.println("time:"+(System.currentTimeMillis()-before));
                        //Image newImage = Image.createRGBImage(newbuffer, width, height, false);
                        // orig = null;
                        // newbuffer = null;
                        originalImage=null;      
                         System.gc(); //  
                         return newImage;
                    }

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.

xsi3rr4x (30 views)
2014-04-15 18:08:23

BurntPizza (27 views)
2014-04-15 03:46:01

UprightPath (42 views)
2014-04-14 17:39:50

UprightPath (24 views)
2014-04-14 17:35:47

Porlus (41 views)
2014-04-14 15:48:38

tom_mai78101 (63 views)
2014-04-10 04:04:31

BurntPizza (123 views)
2014-04-08 23:06:04

tom_mai78101 (222 views)
2014-04-05 13:34:39

trollwarrior1 (189 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!