2016~4.12Android 之图片处理

努力从今天开始

   转发地址 http://blog.csdn.net/heng615975867/article/details/50618377

  今天研究一下Android的图片的使用问题

   做项目中遇到头像问题,在分辨率不同的设备上需要显示相同的大小,我的处理方式:

   //获取网络图片

   ImageHttpUtile.setVolleyImageview(bean.stuIcon, holder.stuIcon);
            LayoutParams para;
            para = holder.stuIcon.getLayoutParams();  
            para.height = context.getResources().getDimensionPixelSize(R.dimen.student_icon_height);  
            para.width = context.getResources().getDimensionPixelSize(R.dimen.student_icon_wide);
            holder.stuIcon.setLayoutParams(para);

  以上是获取网络图片,根据不同的设备,设置不同的大小。

  突然想总结一下图片处理的知识

  //读取

  public static Bitmap ReadBitmapById(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        // 获取资源图片  
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }

  //获得圆角bitmap
  public
 static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { 

  int w = bitmap.getWidth(); 
  int h = bitmap.getHeight();
  Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); 
  Canvas canvas = new Canvas(output); 
  final int color = 0xff424242;
  final Paint paint = new Paint(); 
  final Rect rect = new Rect(00, w, h); 
  final RectF rectF = new RectF(rect); 
  paint.setAntiAlias(true);
  canvas.drawARGB(0000); 
  paint.setColor(color); 
  canvas.drawRoundRect(rectF, 1010, paint);// 圆角平滑度为10 
   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmap, rect, rect, paint); 
  return output; 
  }
 

你可能感兴趣的:(android)