Exemplo n.º 1
0
 /** 设置开机图片 */
 public void initImgView() {
   imageview = (ImageView) this.findViewById(R.id.cp1);
   File sdcardDir = Environment.getExternalStorageDirectory();
   String path = sdcardDir.getParent() + "/" + sdcardDir.getName();
   // 得到开机图片
   Bitmap bitmap = BitmapFactory.decodeFile(path + DownLoadImg.LOCAL_DIR + DownLoadImg.IMG_NAME);
   String errorCode = shellRW.getStringValue("errorCode");
   if (bitmap == null || errorCode.equals("") || errorCode.equals("false")) {
     Resources r = this.getResources();
     InputStream is = r.openRawResource(R.drawable.cp1);
     BitmapDrawable bmpDraw = new BitmapDrawable(is);
     bitmap = bmpDraw.getBitmap();
   }
   // 缩放开机图片
   Matrix matrix = new Matrix();
   float iScreenWidth = PublicMethod.getDisplayWidth(this);
   float iScreenHeight = PublicMethod.getDisplayHeight(this);
   float w = iScreenWidth / bitmap.getWidth();
   float h = iScreenHeight / bitmap.getHeight();
   if (w != 1 || h != 1) {
     matrix.postScale(w, h);
     bitmap =
         Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
   }
   imageview.setImageBitmap(bitmap);
 }