Discussion Board

Results 1 to 7 of 7
  1. #1
    Hi, i want to combine my background and text into one image by converting it into bytes then back to an image, but by doing as the codes below, i encounter a illegalArguementException at the this line " im = Image.createImage(rawByte, 0, rawByte.length); "

    is there any idea what happen?



    Code:
        public Image createImageMethod() {
           
            Image blankImage = Image.createImage(getWidth(), getHeight());
            Graphics g = blankImage.getGraphics();
            g.setColor(0,0,0);
            try
            {
            Image backgroundImage= Image.createImage("/picture/background1.png");
             g.drawImage(backgroundImage, 0, 0, Graphics.HCENTER | Graphics.VCENTER);
            }catch(IOException e)
            {}
            
            g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
            g.drawString(text, x, y,Graphics.TOP|Graphics.LEFT);
           
           
            int width = blankImage.getWidth();
            int height = blankImage.getHeight();
            int y = 0;
     
               
            int raw[] = new int[height * width];
           blankImage.getRGB(raw, 0, blankImage.getWidth(), 0, 0, blankImage.getWidth(), blankImage.getHeight());
            byte rawByte[] = new byte[blankImage.getWidth() * blankImage.getHeight() * 4];
            int n = 0;
            for (int i = 0; i < raw.length; i++) {
                int ARGB = raw[i];
                int a = (ARGB & 0xff000000) >> 24;
                int r = (ARGB & 0xff0000) >> 16;
                int green = (ARGB & 0xff00) >> 8;
                int b = ARGB & 0xff;
                rawByte[n] = (byte) b;
                rawByte[n + 1] = (byte) green;
                rawByte[n + 2] = (byte) r;
                rawByte[n + 3] = (byte) a;
                n += 4;
            }
                
    
                
                   // Create the image from the byte array
           im = Image.createImage(rawByte, 0, rawByte.length);    
    
            return im;
        }

  2. #2
    Super Contributor grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    IllegalArgumentException from createImage() indicates that the data is not in a format that createImage() recognizes. createImage() is guaranteed to understand data in PNG format, and might understand other formats, like JPEG.

    If you want to draw RGB data from getRGB(), you need to use Graphics.drawRGB().

  3. #3
    hi grahamhughes ,

    so this means my im=Image.createImage(...) shud change to g.drawRGB() ?

  4. #4
    Super Contributor grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    I have no idea what you are trying to achieve. Why do you convert the image to a byte array, and then back to an Image?

    Why not just:

    Code:
    public Image createImageMethod() {
        Image blankImage = Image.createImage(getWidth(), getHeight());
        Graphics g = blankImage.getGraphics();
        g.setColor(0, 0, 0);
        try {
            Image backgroundImage= Image.createImage("/picture/background1.png");
            g.drawImage(backgroundImage, 0, 0, Graphics.HCENTER | Graphics.VCENTER);
        } catch (IOException e) {
        }
            
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        g.drawString(text, x, y, Graphics.TOP | Graphics.LEFT);
    
        return blankImage;
    }
    Graham.

  5. #5
    if i just do the way you mention, add the above will become one image?

  6. #6
    Super Contributor grahamhughes's Avatar
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,394
    It is already one image.

    You are creating an image, then drawing another image onto it, then writing some text onto the image. End result: one image.

  7. #7
    Hi, thanks for the help, i mange to do that and implement to my codes below by settig the three images frameImage1 -3 and allow it to implement to the gif encoder, base on the codes below am i doing the right way?

    I am stuck till this point, as i allow the user to save this gif image into the local memory of the phone, how should i able to do it?

    Thank you in advance =)

    Code:
     public byte[] saveMethod(Image frameImage1,Image frameImage2,Image frameImage3) {
            System.out.println("HELLO");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            encoder.start(bos);
            encoder.addFrame(frameImage1);
            encoder.addFrame(frameImage2);
            encoder.addFrame(frameImage3);
            encoder.finish();
            
            return bos.toByteArray();
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved