Bebeto
Bebeto

Reputation: 59

How can i save image write it inside the folder after editing in J2ME

Kindly Help me in my problem . Thanks a lot :)

public Image ResizeImage(Image image,int resizedimageWidth,intresizedHeight){
    int[] in = null;
    int[] out = null;
    int imageWidth = image.getWidth();
    int imageHeight = image.getHeight();
    in = new int[imageWidth];
    int dy, dx;
    out = new int[resizedimageWidth * resizedHeight];
    for (int y = 0; y < resizedHeight; y++) {
        dy = y * imageHeight / resizedHeight;
        image.getRGB(in, 0, imageWidth, 0, dy, imageWidth, 1);
        for (int x = 0; x < resizedimageWidth; x++) {
            dx = x * imageWidth / resizedimageWidth;
        out[(resizedimageWidth * y) + x] = in[dx];
        }
    }
    Image resized = Image.createRGBImage(out, resizedimageWidth, resizedHeight, true);
            saveResizedImage(resized.toString().getBytes());
    return resized;
         }

private void saveResizedImage(byte[] bytes) {
    try {
    FileConnection fileConnection = (FileConnection) Connector.open(Utility.getMigoMobileDir() + StringConstants.USERS + StringConstants.SEPERATOR
                + userID + StringConstants.POSTFIX_PNG, Connector.READ_WRITE);
        if (fileConnection.exists()) {
            fileConnection.delete();
        }
        fileConnection.create();
        OutputStream oS = fileConnection.openOutputStream();
        oS.write(bytes);            
        oS.flush();     
        oS.close();         
        fileConnection.close();
        fileConnection = null;
        oS = null;
    } catch (IOException e) {
        e.printStackTrace();
        Utility.exception("[capture] " + e.toString());
    } catch (Exception e) {
        Utility.exception("[capture] " + e.toString());
    }
}

This code above is use to edit(ResizeImage) and save(saveResizedImage) image inside the folder but the output is empty picture.

Upvotes: 0

Views: 94

Answers (1)

arseny
arseny

Reputation: 386

your problem is with the following line

        saveResizedImage(resized.toString().getBytes());

the toString of an object is just a meaningless representation and not the actual data, you should find a way to convert the int[] of the resized image to byte[] and save it.

Upvotes: 0

Related Questions