垂直繪製字符串我想在屏幕上畫一個線,旋轉90度,在一個透明的背景:與透明背景
public static void drawStringWithTransformROT90(String text, int x, int y, int color, Graphics g) {
// create a mutable image with white background color
Image im = Image.createImage(g.getFont().stringWidth(text), g.getFont().getHeight());
Graphics imGraphics = im.getGraphics();
// set text color to black
imGraphics.setColor(0x00000000);
imGraphics.drawString(text, 0, 0, Graphics.TOP|Graphics.LEFT);
int[] rgbData = new int[im.getWidth() * im.getHeight()];
im.getRGB(rgbData, 0, im.getWidth(), 0, 0, im.getWidth(), im.getHeight());
for (int i = 0; i < rgbData.length; i++) {
// if it is the background color (white), set it to transparent
if (rgbData[i] == 0xffffffff) {
rgbData[i] = 0x00000000;
} else {
// otherwise (black), change the text color
rgbData[i] = color;
}
}
Image imageWithAlpha = Image.createRGBImage(rgbData, im.getWidth(), im.getHeight(), true);
Sprite s = new Sprite(imageWithAlpha);
// rotate the text
s.setTransform(Sprite.TRANS_ROT90);
s.setPosition(x, y);
s.paint(g);
}
有沒有更好的方式做到這一點?我應該創建一個旋轉字母表的透明圖像,並使用Sprite
對象繪製它?
部分 – user 2011-04-21 19:02:01
@JánosHarsányi對不起,我錯過了您的請求透明度,希望這應該能夠解決它使用像素和drawRGB()通過諾基亞http://fivedots.coe.psu.ac.th/Software .coe/J2ME /諾基亞%20Articles/Working_witrh_pixels_and_drawRGB_v1_0.pdf – 2011-04-21 21:40:39