如何在移动位图时缩放位图?

时间:2012-10-26 07:26:42

标签: android

触摸我创建并移动位图。现在我想在移动时缩放位图。我该如何带来这种效果?我使用精灵对象来移动它。我想创造一种射击的幻觉。我想这应该由逻辑来实现。

public class SpriteObject {

    private Bitmap bitmap;
    private int x;      
    private int y;  
    private int x_move = 0;
    private int y_move = -1;


    public SpriteObject(Bitmap bitmap, int x, int y) {
        this.bitmap = bitmap;
        this.x = x;
        this.y = y;
    }


    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }


    public void setMoveX(int movex){
        x_move = movex;
    }
    public void setMoveY(int movey){
        y_move = movey;
    }
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }
    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public void draw(Canvas canvas) {
        canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2), y - (bitmap.getHeight() / 2), null);
    }

    public void update(int adj_mov) {
            x += (adj_mov * x_move);
            y += (adj_mov * y_move);

    }
    public void still(int adj_still) {
        x += (adj_still * x_move);
        y += (adj_still * y_move);

    }


}

1 个答案:

答案 0 :(得分:0)

请试试这个:

int h = 100; // height in pixels
int w = 100; // width in pixels

Bitmap photoBitmap = Bitmap.createScaledBitmap(yourSelectedImageBitmap, h, w,true);
相关问题