How to rotate large images

I tried the code for this article:

http://supportforums.BlackBerry.com/T5/Java-development/rotate-and-scale-bitmaps/Ta-p/492524

but it does not work for larger images like 1024 x 768 and rise IllegalArgumentAxception saying that the bitmap is too large.

.

OK, I did something that works for me, but is not perfect at all.

It works well for images of 1024 x 768 and turns them but increases the size of the file (if save you them) for some reason any and loses brightness, but the quality is ok at least for the purposes of my application.

Here's what I do:

(1) I take a bitmap (1024 x 768) and create a new bitmap with 1024 x 1024 - width and height

copy 2) old on the new

(3) turn the new bitmap when you rotate a matrix size NxN and return a new bitmap rotated

(4) create a new bitmap to the tour final, but cut the part added so that you get an image size of 768 x 1024

Here's the code. It could be optimized again especially in the rotateSquareImage() method where you can work with arrays of regular tables not 2d.

package com.melonmobile.blackberry.pdfscanner.screens;

import net.rim.device.api.system.Bitmap;

public class ImageRotator {

    public Bitmap rotate(Bitmap oldImage) throws Exception {
        int w = oldImage.getWidth();
        int h = oldImage.getHeight();
        int d = Math.max(w, h);
        int amountPxAdded = 0;
        if (w > h) {
            amountPxAdded = w - h;
        }
        Bitmap oldBitmapSquared = new Bitmap(d, d);
        int[] data = new int[w * h];
        oldImage.getARGB(data, 0, w, 0, 0, w, h);
        oldBitmapSquared.setARGB(data, 0, w, 0, 0, w, h);
        Bitmap finalRes = new Bitmap(h, w);
        int fW = finalRes.getWidth();
        int fH = finalRes.getHeight();
        oldImage = null;
        Bitmap rotated = rotateSquareImage(oldBitmapSquared, 90);
        oldBitmapSquared = null;
        data = new int[fW * fH];
        rotated.getARGB(data, 0, fW, amountPxAdded, 0, fW, fH);
        rotated = null;
        finalRes.setARGB(data, 0, fW, 0, 0, fW, fH);
        return finalRes;
    }

    private Bitmap rotateSquareImage(Bitmap oldB, int angle) throws Exception {
        int w = oldB.getWidth();
        int h = oldB.getHeight();
        Bitmap newB = new Bitmap(w, h);
        int[] oldD = new int[w * h];
        int[] newD = new int[w * h];
        oldB.getARGB(oldD, 0, w, 0, 0, w, h);
        int[][] old2d = new int[h][w];
        int[] js;
        int old2dLen = old2d.length;
        int jsLen;
        for (int i = 0; i < old2dLen; i++) {
            js = old2d[i];
            jsLen = js.length;
            for (int j = 0; j < jsLen; j++) {
                js[j] = oldD[i * w + j];
            }
        }
        int[][] rotated = new int[h][w];
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                rotated[i][j] = old2d[h - j - 1][i];
            }
        }
        old2d = null;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                newD[i * w + j] = rotated[i][j];
            }
        }
        rotated = null;
        newB.setARGB(newD, 0, w, 0, 0, w, h);
        return newB;
    }
}

If someone decides to improve Please publish an improved version, so it could be used by more people.

Tags: BlackBerry Developers

Similar Questions

  • How to rotate the image in movie maker a few degrees to get it exactly horizontal

    If my camera was slightly off level during recording, how I rotate the image a few degrees in Movie Maker to get this level

    I found a copy of 1.9.2.

    Excellent

    Wayne

  • How to rotate the image only once

    Hai, I am very new in the development of blackberry applications. I need an image that need to be done rotate 360 degrees once only. I see so many references here and I know that there is a thread that discuss it, but I can't find the right one.

    Thanks in advance.

    You asked a single rotation - "how to rotate the image only once.

    There is no standard API that provides a rotating image permanently using standard features of BlackBerry.

    The usual way to display animations is demonstrated in this article.

    http://supportforums.BlackBerry.com/T5/Java-development/display-an-animated-GIF/Ta-p/445014

    If you can prepare your animation and package with your application, it will be much easier and more effective. Do you know what pictures you're going to turn?

  • How to rotate the image in the muse of adobe?

    Hello.. I would like to know how to rotate the image in the muse of adobe?

    Use this free widget:

    https://creative.Adobe.com/addons/products/2117#.VXla5jNcOeV

  • How to rotate the image

    How to rotate the image

    There are several ways to rotate an image in Photoshop.

    As mentioned above, using the Image menu allows you to rotate your entire canvas area. Go to Image > Rotation of Image and select either 180 °, 90 ° CW (clockwise), or 90 ° CCW (the clockwise direction).

    In the picture menu, you can also select arbitrary to indicate the exact amount that you want to rotate your image:

    You can also use free transform to rotate an image or an individual layer. Go in Edit > transform , then select Rotate. Use the handles that appear around your image to rotate. Note that this method may require you to resize your canvas size to include your entire image (to do this, you can use the Crop function).

    Feel free to answer all questions!

    See you soon,.

    Kendall

  • How to rotate an image

    Myfirstwebsite tutorial, said of second part, ' "use the selection tool to select the Twitter button and then use one of the corner handles to rotate the image to Twitter so that it display vertically, as shown in Figure 15"»

    For me, the angle handles moving the image in four directions but do not turn it.

    Hey Joe,

    This is how you can rotate a picture, http://project02.businesscatalyst.com/Jing/2012-08-28_2049.swf

    Let me know more details.

    Kind regards

    Abhishek Maurya

  • Mac pro with monitor Dell P2414H book: how to rotate the image displayed in mode portrait when I rotate the monitor 90 degrees

    I have a mac book pro retina bought in 2014 which I use with a Dell P2414H monitor.

    I bought this monitor because it can turn up to the vertical position ('portrait'), but when I do that the image of the screen does not turn with it.

    I called Dell and they said that it is a problem to solve with Apple.

    Does anyone else have this problem? and it got fixed?

    This is the Office Mac Pro forum. I asked that your post be moved to the MacBook Pro laptop forum.

  • How to rotate an image of flat piece smoothly?

    I tried to design a Logo that contains a coin inside.

    and in the process of design, I tried to make a corner 45 degree flip effect, but found must achieve...

    It's like that

    latest?cb=20130113020535flip for this to be latest?cb=20140119014215

    I knew this could be done by the perspective tool... but it's so hard to return this piece beautifully...

    ... any tips?     enjoy

    Welcome to visit my site, Aaron men Style

    Photoshop extended has 3D functionality, you may want to take a look.

  • Hi, is it possible to rotate an image in Firefox, and if so, how?

    I read a doc pdf on Firefox that was recorded on the side, how to rotate 90 degrees?

    Try right-click on the PDF page image and select rotation. In my opinion, he's 90 degrees at a time.

    If this answer solved your problem, please click 'Solved It' next to this response when connected to the forum.

    You must update some plug-ins:

  • How can I rotate an image of a pivot point?

    Hello

    I have a problem, the rotation VI Imaq only rotate an image at its Center. My problem is that I need a pivot known to this point. How can I achieve this?

    Thank you

    Francesco.

    This message can help?
    http://forums.NI.com/T5/LabVIEW/rotate-an-image-by-specified-pixel/TD-p/2570453

  • How to convert an image large parts of images? means split a jpg to several sub vivid image. (this sub image can partner in this big picture)

    Hi friends...

    How to convert an image large parts of images? means split a jpg to several sub vivid image. (this subimages can partner in this great image) any help

    In the example, I created both images and them added together, and the reverse can be done in the same way.

  • How to remove lid on OfficeJet Pro 8600 for the digitization of large images

    I'm an artist wanting to analyze some of my larger images.  This is not possible unless I can remove the cover (or it opens and go completely flat) on my OfficeJet Pro 8600.  Please tell me if this is possible and, if so, how.  Thank you!

    Sorry, that the 8600 Officejet is not designed to have the cover removed for scanning.  There is a wire bundle between the ADF on the lid and the interns of printer below.

  • I recently bought two pictures for my youth group. When I looked behind them image is a larger image, but, when I downloaded it it's a smaller image. How can I get the enlarged image?      #93598775 &amp; #18109349

    I recently bought two pictures for my youth group. When I looked behind them image is a larger image, but, when I downloaded it it's a smaller image. How can I get the enlarged image?#93598775 & #18109349

    Follow these steps: I downloaded my 10 free images and they all have the Adobe watermark on them, so I can't use them. Why do they have a watermark on them?

  • How do I pan through a large image?

    Hello! I use first elements 13 on Win 8.1, 8 GB of RAM.

    I have a large image (2712 x 896, 96 DPI, jpeg-1.56 MB). I would like to add to my movie (1920 x 1080) and move it into the image. So I would like to than the video to begin to show the left side of the wide image and move slowly in to show the Center, then the right side of the image, more than 15 seconds or more.

    So I add the image on my calendar. I checked the image file is right-side-around the top outside Parliament, but by default, it appears rotated 90 degrees to the left forward. If I use the window effects applied to Rotate clockwise by 90 degrees. Then I click the Pan tool and Zoom. This tool shows my new image rotate 90 degrees to the left, so it is facing backwards in the video (see attached screencap). He wants pan to the bottom of the image to the top, and I see no option to rotate the image in the pan/zoom tool. Is it possible to orient my image the correct way for panning?

    I tried to set a framework for the development of pan in 'down' of the image (that is, the left side of the image, where I would like to begin the Pan) and a framework for development at the "top" of the image (i.e. the right side of the image). In this case, the preview window displays the image right-side-up top, but it always from a height from top to bottom. So, I see a lot of black (from the "border" well below the image), then the center of the image slides by (properly oriented, but moving up and down) and then I see more black of the border above the image. If PE is very confused about the image. :-)

    Snap5.gif

    First, you'll need to rotate the original photo using Photoshop Elements. Don't just apply the Rotate property in Premiere Elements or other settings won't make sense.

    You say that you have insured that the photo is correctly oriented outside of Premiere Elements, but simply turning it correctly in the Organizer does NOT change orientation or rotation of the image. You must change the original photo in Photoshop Elements.

    Once your original photo is correctly oriented, it's as simple as using keyframes in Motion or the tool panoramic and Zoom pan through it.

  • How to resize layer with a large image of the layer mask?

    Hi all

    How to resize the image on the layer mask?

    * document - doc.width, doc.height

    * mask - activeLayer.bounds

    * and how to take the coordinates in the image with the mask, if the image is larger than the size of the document?

    01.jpg

    2014, use it at your own risk.

    #target "photoshop - 70.032»

    If (app.documents.length > 0) {}

    Var ref = new ActionReference();

    ref.putEnumerated (charIDToTypeID ("Lyr"), charIDToTypeID ("Ordn"), charIDToTypeID ("Trgt"));

    var layerDesc = executeActionGet (ref);

    var layerMaskEnabled = layerDesc.getBoolean (stringIDToTypeID ("userMaskEnabled"));

    If (layerMaskEnabled == true) {}

    // =======================================================

    var idsetd = charIDToTypeID ("setd");

    var desc4 = new ActionDescriptor();

    var idnull = charIDToTypeID ("null");

    var ref1 = new ActionReference();

    var idLyr = charIDToTypeID ("Lyr");

    var idOrdn = charIDToTypeID ('Ordn');

    var idTrgt = charIDToTypeID ("Trgt");

    Ref1.putEnumerated (idLyr, idOrdn, idTrgt);

    Desc4.putReference (idnull, ref1);

    idT var = charIDToTypeID ("T");

    var desc5 = new ActionDescriptor();

    var idUsrM = charIDToTypeID ("rocket");

    Desc5.putBoolean (idUsrM, false);

    var idLyr = charIDToTypeID ("Lyr");

    Desc4.putObject (idLyr, idT, desc5);

    executeAction (idsetd, desc4, DialogModes.NO);

    };

    Alert (app.activeDocument.activeLayer.bounds)

    };

Maybe you are looking for

  • Media browser does not show most of the photos under iCloud photo library

    I use iCloud photo library. I have 50 GB of space to iCloud, and I use only 17. My camera has 2.2 GB of free local space. And yet, when I save photos, their local copies are removed almost immediately. This means that the media browser (UIImagePicker

  • Tecra M2: Question on the new hard drive

    Dear Sir.I want to improve my laptop tecra m2 1.8 Ghz by installing a new hard drive: wich one should I choose?I mean a hard drive faster and more 'heavy '. Thanks in advanceDr. Weekx R

  • Windows ISO xp?

    I have an old xp laptop computer with a product key... it's broken. is an iso file of windows xp with sp3 can I download and install? Windows xp home

  • How to uninstall and re-install Windows Media Player 12?

    Help! I had a windows 7 Packard Bell Pc load pretty much since when Windows 7 is released. Media Player was always full of problems (mainly loading websites Web and any old logo in the directory of the image). Now, he won't play same videos web based

  • How to write a text on an image data

    Hello I am facing a problem where I am suppose to write a particular text string, then tagg it with the ie.write of the image on the image and save it, also when retrieving images, it should show the data written to the image respectively. Please let