Search code examples
java-menokiamidplcduijsr75

fix a splash screen image to display in j2me


In my j2me App I have tried canvas which works great on Nokia phone but doesn't run on samsung. For that I have to switch to some FORM which in both cases works but only issue is of size, if I create smaller image to fit for both phone screens, one (samsung) shows that ok but other (nokia) leaves a lot more space and vice versa.

I need to have code that could stretch my image and just fix if to the screen size which I basically get by form.getHeight() and form.getWidth() property. I wonder if there is property of Image.createImage(width, height) then why doesn't it stretch it to the value I provide?

my code for that is below

try {
        System.out.println("Height: " + displayForm.getHeight());
        System.out.println("Width: " + displayForm.getWidth());
        Image img1 = Image.createImage("/bur/splashScreen1.PNG");
        img1.createImage(displayForm.getHeight(), displayForm.getWidth()); 
        displayForm.append(new ImageItem(null, img1, Item.LAYOUT_CENTER, null));
    } catch (Exception ex) {
    }

Image enter image description here


Solution

  • wonder if there is property of Image.createImage(width, height) then why doesn't it stretch it to the value I provide?

    Parameters in this method have nothing to do with stretching, see API javadocs:

     public static Image createImage(int width, int height)
    
        Creates a new, mutable image for off-screen drawing.
            Every pixel within the newly created image is white.
            The width and height of the image must both be greater than zero.
    
        Parameters:
            width - the width of the new image, in pixels
            height - the height of the new image, in pixels
    

    Image class (API javadocs) has two more createImage methods that use parameters called "width" and "height" - one with six, another with four arguments but none of these has anything to do with stretching.

    • In createImage with six arguments, width and height specify size of the region to be copied (without stretching) from source image.

    • In method with four arguments, width and height specify how to interpret source ARGB array, without these it would be impossible to find out if, say, array of 12 values represents 3x4 image or 4x3. Again, this has nothing to do with stretching.