如何将位图图像转换为可绘制图像,以便它将显示在另一个位图图像上

时间:2012-05-14 04:35:35

标签: java android

我有一个扩展视图的类...其中我有两个位图图像显示一个在另一个....为此我想尝试将一个位图图像转换为可绘制的图像,但它是dsnt在第一个展示我正在尝试的是.....

public class ShowCanvas extends View {

Bitmap CanvasBitmap;
Bitmap ScaledBitmap;
Bitmap smallbitmap;
private static final int INVALID_POINTER_ID = -1;

private Drawable mImage;
private float mPosX;
private float mPosY;

private float mLastTouchX;
private float mLastTouchY;
private int mActivePointerId = INVALID_POINTER_ID;

private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;



public ShowCanvas(Context context) {
    super(context);
    // TODO Auto-generated constructor stub

    ScaledBitmap = DrawView.scaled;



**when i get the image from drawable it shows over the first one...**   

mImage = getResources()。getDrawable(R.drawable.dress01);

但是当我使用它时,它会显示图像......

mImage = new BitmapDrawable(getResources(),Dress.bitmap);

    System.out.println("Drawable" + mImage);



    int X = mImage.getMinimumWidth();

    int Y = mImage.getIntrinsicHeight();

    System.out.println(" Rough" + X + "\t" + Y);


    mImage.setBounds(0, 0, mImage.getIntrinsicWidth(),
            mImage.getIntrinsicHeight());

}

public void setBitmap(Bitmap bitmap) {
    // TODO Auto-generated method stub
    CanvasBitmap = bitmap;

    System.out.println("CanvasBitmap" + CanvasBitmap);

    int X = CanvasBitmap.getHeight();
    int Y = CanvasBitmap.getWidth();

    System.out.println("CanvasBitmap " + X + "\t" + Y);

}



@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    Paint mpaint = new Paint();
    canvas.save();

    canvas.drawBitmap(ScaledBitmap, 0, 0, mpaint);

    mImage.draw(canvas);

    Log.i("Debug", "mImage.draw(canvas)");

    canvas.restore();

}

}

1 个答案:

答案 0 :(得分:3)

Drawable d =new BitmapDrawable(bitmap); 

使用它将位图图像转换为可绘制的。