Zooming Bitmap images in blackberry Mobile Development

In our projects we may need zoom in or out images before they display.so this method will do it for you.simple but useful. you must have access to signed api's in blackberry
   private Bitmap ZoomImage(String FilePath, int zoomFactor) {

    Bitmap pictureDisplayed = null;

    try {
        // open the file connection to retrieve the picture from the saved
        // place
        FileConnection fconnForZoom = (FileConnection) Connector
        .open("file://" + FilePath);
        if (fconnForZoom.exists()) {
        InputStream input = fconnForZoom.openInputStream();
        int available = (int) fconnForZoom.fileSize();
        byte[] data = new byte[available];
        input.read(data, 0, available);
        EncodedImage ePictureOriginal = EncodedImage
        .createEncodedImage(data, 0, data.length);
        ePictureOriginal.setScale(20);
        if (zoomFactor == 100) {
            int scaleFP = Fixed32.tenThouToFP((int) 1 * 10000);
            EncodedImage ePictureDisplayed = ePictureOriginal
            .scaleImage32(scaleFP, scaleFP);
            pictureDisplayed = ePictureDisplayed.getBitmap();
        } else if (zoomFactor == 200) {
            int scaleFP = Fixed32.tenThouToFP((int) 2 * 10000);
            EncodedImage ePictureDisplayed = ePictureOriginal
            .scaleImage32(scaleFP, scaleFP);
            pictureDisplayed = ePictureDisplayed.getBitmap();
        }
        // I keep in memory the bitmap to get a smooth picture scrolling

        input.close();
        } else {
        pictureDisplayed = new Bitmap(0, 0);
        }

        fconnForZoom.close();

    } catch (Exception ioe) {

    }

    return pictureDisplayed;

    }

No comments:

Post a Comment

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...