gpt4 book ai didi

java - 在 BB 上的位图上绘制位图

转载 作者:行者123 更新时间:2023-12-02 00:16:50 25 4
gpt4 key购买 nike

我想在位图上绘制位图..我不知道我做错了什么,因为我希望这能起作用。有人可以指出我的错误吗?所以我想在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);
}

}

最佳答案

您需要创建一个 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);
}
}

关于java - 在 BB 上的位图上绘制位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11768386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com