gpt4 book ai didi

android - android中位图的大小

转载 作者:行者123 更新时间:2023-11-29 22:09:38 25 4
gpt4 key购买 nike

我有一张位图:

    private Bitmap bitmap;

public newStar(Context context) {
super(context);

}

@Override
protected void onDraw(Canvas canvas) {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.star_bez_nog);
canvas.drawBitmap(bitmap, 100, 100, null);
}
}

我如何更改此位图的大小并在我的 Activity 中进行绘制?

最佳答案

Use the below code::
Bitmap b = returnBitmap(mIcon_val,150,150);////where mIcon_val is bitmap to resize


private Bitmap returnBitmap(Bitmap mIcon_val,int width,int height){
Matrix matrix = new Matrix();
if(width==0)
width = mIcon_val.getWidth();
if(height==0)
height = mIcon_val.getHeight();
matrix.postScale((float)width/mIcon_val.getWidth(), (float)height/mIcon_val.getHeight());
Bitmap resizedBitmap = Bitmap.createBitmap(mIcon_val, 0, 0, mIcon_val.getWidth(), mIcon_val.getHeight(), matrix, true);
return resizedBitmap
}

关于android - android中位图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9973153/

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