在BB上的位图上绘制位图

时间:2012-08-01 22:16:50

标签: java blackberry

我想在位图上绘制一个位图..我不知道我做错了什么因为我希望这个有用。有人可以指出我的错误吗?所以我想在bitmapImage上绘制bitmapImage2。我相信我的错是使用Graphics.create(位图)

    package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

public class BitmapFieldDemo extends UiApplication 
{
    public static void main(String[] args)
    {
        BitmapFieldDemo theApp = new BitmapFieldDemo(); 
        theApp.enterEventDispatcher(); 
    }

    public BitmapFieldDemo() 
    { 
        pushScreen(new BitmapFieldDemoScreen()); 
    } 
}

class BitmapFieldDemoScreen extends MainScreen
{
    Graphics g;
    Bitmap bitmapImage = Bitmap.getBitmapResource("red.png");
    Bitmap bitmapImage2 = Bitmap.getBitmapResource("background.png");

    public BitmapFieldDemoScreen ()
    {

        setTitle("Bitmap Field Demo");
        // image i want to draw on
        Graphics.create( bitmapImage );
        // bitmapfield
        BitmapField fieldDemo = new BitmapField(bitmapImage);             
        add(fieldDemo);

    }

    public void paint(){

        super.paint(g);
        // image that needs to be drawn on the bitmapImage
        g.drawBitmap(50, 50, bitmapImage2.getWidth(), bitmapImage2.getHeight(), bitmapImage2, 0, 0);
    }

}

1 个答案:

答案 0 :(得分:2)

您需要从Graphics创建一个Bitmap对象,并需要在您创建的Bitmap实例上绘制第二个Graphics。请尝试以下代码。

class BitmapFieldDemoScreen extends MainScreen {    
    Bitmap bitmapRed = Bitmap.getBitmapResource("red.png");
    Bitmap bitmapBG = Bitmap.getBitmapResource("background.png");

    public BitmapFieldDemoScreen () {
        setTitle("Bitmap Field Demo");        

        // draw the bitmapRed on top of bitmapBG        
        Graphics grahpicsBg = Graphics.create(bitmapBG);
        grahpicsBg.drawBitmap(50, 50, bitmapRed.getWidth(), bitmapRed.getHeight(), bitmapRed, 0, 0);

        // now bitmapBg is changed        

        BitmapField fieldDemo = new BitmapField(bitmapBG);             
        add(fieldDemo);
    }
}