Java me 使用透明背景垂直绘制字符串
我想在屏幕上画一条线,在透明背景上旋转90度:Java me 使用透明背景垂直绘制字符串,java-me,Java Me,我想在屏幕上画一条线,在透明背景上旋转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.ge
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);
}
public static void drawStringWithTransformROT90(字符串文本、整数x、整数y、整数颜色、图形g){
//创建具有白色背景色的可变图像
Image im=Image.createImage(g.getFont().stringWidth(text),g.getFont().getHeight());
Graphics imGraphics=im.getGraphics();
//将文本颜色设置为黑色
imGraphics.setColor(0x00000000);
imGraphics.drawString(文本,0,0,Graphics.TOP | Graphics.LEFT);
int[]rgbData=new int[im.getWidth()*im.getHeight()];
getRGB(rgbData,0,im.getWidth(),0,0,im.getWidth(),im.getHeight());
对于(int i=0;i
有没有更好的办法?我是否应该创建一个旋转字母表的透明图像,并使用Sprite
对象绘制它?如果用于绘制,可以指定
正如在中发现的那样,如果使用
Image.createImage(int,int)创建Image
,则该类不属于Java Microedition API的一部分,因此无法使用JME代码>它将有一个白色背景颜色:(@János Harsányi抱歉,我错过了你的要求中的透明度。希望这可以修复它与诺基亚的像素和drawRGB()一起工作
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.Sprite;
public class MyCanvas extends Canvas {
public void paint(Graphics g) {
//The text that will be displayed
String s="java";
//Create the blank image, specifying its size
Image img=Image.createImage(50,50);
//Create an instance of the image's Graphics class and draw the string to it
Graphics gr=img.getGraphics();
gr.drawString(s, 0, 0, Graphics.TOP|Graphics.LEFT);
//Display the image, specifying the rotation value. For example, 90 degrees
g.drawRegion(img, 0, 0, 50, 50, Sprite.TRANS_ROT90, 0, 0, Graphics.TOP|Graphics.LEFT);
}
}