您的位置:首页 > 移动开发 > Android开发

2016~4.12Android 之图片处理

2016-04-12 17:36 519 查看
努力从今天开始

   转发地址 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(0, 0, w, h); 

  final RectF rectF = new RectF(rect); 

  paint.setAntiAlias(true);

  canvas.drawARGB(0, 0, 0, 0); 

  paint.setColor(color); 
  canvas.drawRoundRect(rectF, 10, 10, paint);// 圆角平滑度为10 

   paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

  canvas.drawBitmap(bitmap, rect, rect, paint); 
  return output; 
  }
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android