如何将图像加载到Android画布上

时间:2014-04-23 23:15:15

标签: android

我一直在尝试从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() {
    }
}

0 个答案:

没有答案