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; }

Reply With Quote

