android 游戏开发过程中让图片自适应
ndroid游戏开发或者应用,使背景位图自适应手机分辨率的方法(转)
//得到图片资源
dstbmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg8);
// 获取系统分辨率
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
Matrix matrix = new Matrix();//使用matri控制图形变换
float w = ((float) display.getWidth() / dstbmp.getWidth());//屏幕宽度除图片宽度
float h = ((float) display.getHeight() / dstbmp.getHeight());//屏幕高度除图片高度
matrix.postScale(w, h);// 获取缩放比例
// 根据缩放比例获得新的位图
background = Bitmap.createBitmap(dstbmp, 0, 0, dstbmp.getWidth(), dstbmp.getHeight(), matrix, true);
// 绘制背景
canvas.drawBitmap(background, 0, 0, null);