在黑莓中旋转任意角度的位图图像

时间:2012-08-25 08:40:58

标签: blackberry bitmap

我是Blackberry的新手。我有一个图像,我需要根据用户的输入旋转到一定程度..我试过搜索,但似乎无法找到任何东西。任何人都能指出我正确的方向吗?

3 个答案:

答案 0 :(得分:1)

有一个J2ME Army Knife library,请检查一下。

它确实包含旋转功能。

答案 1 :(得分:1)

这是Blackberry知识库文章的一部分.. 通过你的位图&获取旋转位图的此函数的角度。

public static 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, <Angle>);
    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 static 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;
}

答案 2 :(得分:1)

请按照以下步骤操作:

  

从此链接下载 zip 文件:BitmapRotate位于下方。

     

从该项目中添加 ImageManipulator.java 并将其添加到您的项目中;

     

并使用以下链接中的代码:RotatingBitmap on Blackberry

我认为这有助于你;

使用下面的BitmapRotate.zip代码来旋转此链接中的图像:

Bitmap rotation in blackberry