android开发中如何对图片进行处理

  介绍

这篇文章给大家介绍android开发中如何对图片进行处理,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1,创建一个Java类CircleImageView把下面的代码复制过去,报错的导包

包de.hdodenhof.circleimageview;
  进口edu.njupt.zhb.main.R;
  进口android.content.Context;
  进口android.content.res.TypedArray;
  进口android.graphics.Bitmap;
  进口android.graphics.BitmapShader;
  进口android.graphics.Canvas;
  进口android.graphics.Color;
  进口android.graphics.Matrix;
  进口android.graphics.Paint;
  进口android.graphics.RectF;
  进口android.graphics.Shader;
  进口android.graphics.drawable.BitmapDrawable;
  进口android.graphics.drawable.ColorDrawable;
  进口android.graphics.drawable.Drawable;
  进口android.util.AttributeSet;
  进口android.widget.ImageView;
  
  公开课CircleImageView延伸ImageView {
  
  私有静态最终ScaleType SCALE_TYPE=ScaleType.CENTER_CROP;
  
  私有静态最终的位图。配置BITMAP_CONFIG=Bitmap.Config.ARGB_8888;
  私有静态最终int COLORDRAWABLE_DIMENSION=1;
  
  私有静态最终int DEFAULT_BORDER_WIDTH=0;
  私有静态最终int DEFAULT_BORDER_COLOR=Color.BLACK;
  
  私人最终RectF mDrawableRect=new RectF ();
  私人最终RectF mBorderRect=new RectF ();
  
  私人最终矩阵mShaderMatrix=新矩阵();
  私人最终油漆mBitmapPaint=new油漆();
  私人最终油漆mBorderPaint=new油漆();
  
  私人int mBorderColor=DEFAULT_BORDER_COLOR;
  私人int mBorderWidth=DEFAULT_BORDER_WIDTH;
  
  私人位图mBitmap;
  私人BitmapShader mBitmapShader;
  私人int mBitmapWidth;
  私人int mBitmapHeight;
  
  私人mDrawableRadius浮动;
  私人mBorderRadius浮动;
  
  私人布尔mReady;
  私人布尔mSetupPending;
  
  公共CircleImageView(上下文语境){
  超级(上下文);
  }
  
  公共CircleImageView(上下文语境,AttributeSet attrs) {
  这(上下文、attrs 0);
  }
  
  公共CircleImageView(上下文语境、AttributeSet attrs int defStyle) {
  超级(上下文、attrs defStyle);
  super.setScaleType (SCALE_TYPE);
  
  TypedArray=上下文。obtainStyledAttributes (attrs R.styleable。CircleImageView defStyle 0);
  
  mBorderWidth=a.getDimensionPixelSize (R.styleable。CircleImageView_border_width DEFAULT_BORDER_WIDTH);
  mBorderColor=a.getColor (R.styleable。CircleImageView_border_color DEFAULT_BORDER_COLOR);
  
  a.recycle ();
  
  mReady=true;
  
  如果(mSetupPending) {
  设置();
  mSetupPending=false;
  }
  }
  
  @Override
  公共ScaleType getScaleType () {
  返回SCALE_TYPE;
  }
  
  @Override
  公共空间setScaleType (ScaleType ScaleType) {
  如果(scaleType !=SCALE_TYPE) {
  把新IllegalArgumentException (String.format (“ScaleType % s干净自己的不支持,ScaleType));
  }
  }
  
  @Override
  保护空白> & lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比;
  & lt; resources>
  & lt; declare-styleable name=癈ircleImageView"祝辞
  & lt; attr name=癰order_width"格式=癲imension"/比;
  & lt; attr name=癰order_color"格式=癱olor"/比;
  & lt;/declare-styleable>
  & lt;/resources>
  

3,接下来就是使用了,直接在布局文件中使用,具体使用如下:
直接创建一个自定义的CircleImageView ,src属性设置你要改变成圆形的图片

& lt; RelativeLayout xmlns: android=癶ttp://schemas.android.com/apk/res/android"   xmlns:工具=癶ttp://schemas.android.com/tools"   android: layout_width=癿atch_parent"   android: layout_height=癿atch_parent"   android:背景=? ff00ff"   比;      & lt; com.example.circleimageview.CircleImageView   android: id=癅 + id/imageview"   android: layout_width=?00 dp"   android: layout_height=?00 dp"   android: layout_centerInParent=皌rue"   android: src=https://www.yisu.com/zixun/癅drawable/control_image”/>         

关于android开发中如何对图片进行处理就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。

android开发中如何对图片进行处理