任何问题请联系WX:uu16853

买模板送网站采集器 让你轻松放开双手运营网站!

购买更多有优惠!

Android UI开发专题(五) Bitmap和Canvas实例 Android开发技术

  在Android UI开发专题的前五节我们讲到的东西主要是基础和理论内容,从本次Android123将通过实例代码来演示,本次主要是Bitmap和Canvas类的使用,根据要求缩放Bitmap对象并返回新的Bitmap对象。centerToFit方法一共有4个参数,返回一个Bitmap类型,第一个参数为原始的位图对象,width和height分别为新的宽和高,而Context是用来加载资源的上下文实例。   Bitmap centerToFit(Bitmap bitmap, int width, int height, Context context) {        final int bitmapWidth = bitmap.getWidth(); //获取原始bitmap的宽度        final int bitmapHeight = bitmap.getHeight();         if (bitmapWidth < width || bitmapHeight < height) {             int color = context.getResources().getColor(R.color.window_background); //从资源读取背景色             Bitmap centered = Bitmap.createBitmap(bitmapWidth < width ? width : bitmapWidth,                    bitmapHeight < height ? height […]

100% Secure Checkout

PayPal / MasterCard / Visa