我有一个项目,其中的位图比屏幕尺寸大。我想调整它的大小以完全适合屏幕。我没有标题栏,并且处于全屏模式。这是我的非工作代码:
public class ScopView extends View
{
private Scop thescop;
public ScopView(Context context, Scop newscop)
{
super(context);
this.thescop = newscop;
}
@Override
public void onDraw(Canvas canvas)
{
Bitmap scopeBitmap;
BitmapFactory.Options bfOptions = new BitmapFactory.Options();
bfOptions.inDither = false;
bfOptions.inPurgeable = true;
bfOptions.inInputShareable = true;
bfOptions.inTempStorage = new byte[32 * 1024];
scopeBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.scope, bfOptions);
scopeBitmap.createScaledBitmap(scopeBitmap, SniperActivity.Width, SniperActivity.Height, false);
canvas.drawBitmap(scopeBitmap, SniperActivity.scopx, SniperActivity.scopy, null);
}
}
虽然在这里是 createScaledBitmap 方法,但我使用它本身作为源,并使用 Activity 中的一些变量来从屏幕首选项中检索窗口高度和宽度。
最佳答案
您可以使用下面的代码来调整位图的大小。
int h = 320; // Height in pixels
int w = 480; // Width in pixels
Bitmap scaled = Bitmap.createScaledBitmap(largeBitmap, h, w, true);
关于Android - 使位图适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10257674/