gpt4 book ai didi

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

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

我有一个扩展 View 的类...其中我有两个位图图像可以相互显示...为此我正在尝试将一个位图图像转换为可绘制图像,但它不可用显示第一个我正在尝试的内容......

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();

}

}

最佳答案

Drawable d =new BitmapDrawable(bitmap); 

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

关于java - 如何将位图图像转换为可绘制图像,以便将其显示在另一个位图图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10577548/

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