0

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

    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);
    }

}
4

2 回答 2

2

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

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);
    }
}
于 2012-08-02T07:24:24.263 回答
1

试试这个代码 -

    final Bitmap bitmapImage =Bitmap.getBitmapResource("red.png");
    VerticalFieldManager top = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR | Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | Field.USE_ALL_WIDTH){
        public void paint(Graphics graphics) {
            graphics.drawBitmap(0, 0, bitmapImage.getWidth(),
                    bitmapImage.getHeight(), bitmapImage, 0, 0);
            super.paint(graphics);
        }

    };

Bitmap bitmapImage2 = Bitmap.getBitmapResource("background.png");
top .add(new BitmapField(bitmapImage2));
add(top);
于 2012-08-02T05:13:52.867 回答