Search This Blog

Saturday, 28 April 2012

Function to resize image through coding in Blackberry

Hello friends,
as i posted this earlier,but i think a function can be more helpful then a hard coding . So, here is the function to resize an image.

public Bitmap resize(String src,int width,int height){//src = ur filename with extension for ex: "abc.jpg", width=rreq. width,height=req. height//
        int oolddWidth;
        int oolddHeight;
        int ddispplayWidth;
        int ddispplayHeight;
        EncodedImage eih1 = EncodedImage.getEncodedImageResource(src);
        oolddWidth = eih1.getWidth();
        oolddHeight = eih1.getHeight();
        ddispplayWidth = width;
            ddispplayWidth = eih1.getWidth();
        ddispplayHeight = height;
            ddispplayHeight = eih1.getHeight();
            int nnumeerator = net.rim.device.api.math.Fixed32.toFP(oolddWidth);
            int ddenoominator = net.rim.device.api.math.Fixed32.toFP(ddispplayWidth);
            int wwidtthScale = net.rim.device.api.math.Fixed32.div(nnumeerator, ddenoominator);
            nnumeerator = net.rim.device.api.math.Fixed32.toFP(oolddHeight);
            ddenoominator = net.rim.device.api.math.Fixed32.toFP(ddispplayHeight);
            int hheighhtScale = net.rim.device.api.math.Fixed32.div(nnumeerator, ddenoominator);
            EncodedImage newEih1 = eih1.scaleImage32(wwidtthScale, hheighhtScale);
            final Bitmap header1 = newEih1.getBitmap();
            return header1;

No comments:

Post a Comment