gpt4 book ai didi

android - 如何设置绘制的位图宽度和高度

转载 作者:行者123 更新时间:2023-11-29 21:13:00 26 4
gpt4 key购买 nike

拜托,我想设置位图图像的大小。我从 stackover flow 搜索了它,但我不明白,我很无聊。

public class Circle extends View{
float y=300 ;


public Circle(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas c){
super.onDraw(c);

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
c.drawBitmap(myBitmap,y,0,null);
Bitmap myBitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
c.drawBitmap(myBitmap,y+100,0,null);
invalidate();
}
}

它显示图像的原始大小,但我希望它根据不同的屏幕大小而改变。我已经知道如何在不同的屏幕上更改它,但我还不知道如何设置位图大小。 (我正在使用 API min-10)。请给我建议!!

最佳答案

你必须缩放它:

mBitmap = Bitmap.createScaledBitmap(mBitmap, newWidth, newHeight, true);

关于android - 如何设置绘制的位图宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207635/

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