我一直在尝试从Android绘制到画布上的位图图像,所有显示的都是一个空白的白色屏幕。每当我的应用程序启动时,我在我的游戏中调用它 - 视图类扩展View
并覆盖onDraw
方法:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Player {
private int x, y;
private Bitmap bmp;
private FileInputStream s;
File file;
public Player(int x,int y) {
this.x = x;
this.y = y;
}
public void render(Canvas c) throws FileNotFoundException, IOException {
file = new File("C:\\Users\\Anonymous\\Desktop");
s = new FileInputStream(file);
bmp = BitmapFactory.decodeStream(s);
Paint p = new Paint();
c.drawBitmap(bmp,0,0,p);
s.close();
}
public void tick() {
}
}