如何以一定角度插入文本?

时间:2011-12-05 21:54:54

标签: blackberry java-me

如何以90度角将文字插入黑莓。我需要用文字环绕图像(见图):

怎么做?

谢谢!

2 个答案:

答案 0 :(得分:5)

试试这个:

public void paint(Graphics g) {

    //Render horizontal text and image;

    //Render vertical text;        
    g.drawImage(getRotatedText(text), x, y, Graphics.LEFT | Graphics.TOP);
}

public Image getRotatedText(String text) {

    int width = //horizontal text width considering the current font
    int height = //horizontal text font height

    final Image img = Image.createImage(width, height);
    Graphics gx = img.getGraphics();
    gx.drawString(text, 0, 0, Graphics.LEFT | Graphics.TOP);
    gx = null;

    int[] rowData = new int[width];
    int[] rotatedData = new int[width * height];

    int rotatedIndex = 90;
    for (int i = 0; i < height; i++) {
        img.getRGB(rowData, 0, width, 0, i, width, 1);

        for (int j = 0; j < width; j++) {
            rotatedIndex = angle == 90 ? (height - i - 1) + j * height
                    : (angle == 270 ? i + height * (width - j - 1)
                    : width * height - (i * width + j) - 1);
            rotatedData[rotatedIndex] = rowData[j];
        }
    }

    if (angle == 90 || angle == 270) {
        return Image.createRGBImage(rotatedData, height, width, true);
    } else {
        return Image.createRGBImage(rotatedData, width, height, true);
    }
}

答案 1 :(得分:0)

如果您能够定位OS6 +,那么Graphics.drawTextOnPath(...)就是您想要的。