android 头像修改

这篇博客分享了如何在Android应用中实现头像修改的功能。通过参考并整理相关代码,作者创建了一个自定义头像选择的DEMO,允许用户从系统相册选取或直接拍照来更新头像。DEMO的截图和关键代码片段被提供,同时提供了源码的下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/xiaanming/article/details/18730223看了这篇博客,整理出自己需要的代码写了下面这个自定义头像这么一个demo.

效果图:


关键代码:

/***
 * 头像控件
 * @author LanYan
 *
 */
@SuppressLint({ "ClickableViewAccessibility", "DrawAllocation" })
public class PhotoImageView extends View implements OnClickListener{


	private Paint mPaint;
	private Bitmap mBitmap;
	private int newValue;
	private int mWidth;
	private int mHeight;
	private boolean isClickable=true;

	public Bitmap getmBitmap() {
		return mBitmap;
	}

	public void setmBitmap(Bitmap mBitmap) {
		this.mBitmap = mBitmap;
	}

	@SuppressWarnings("deprecation")
	public PhotoImageView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
		int [] arr=ScreenUtil.initialScreen(context);
		mScreenHeight=arr[1];
		mScreenWidth=arr[0];
		Drawable mDrawable=getBackground();
		if(mDrawable!=null){
			setmBitmap(ImageUtils.drawableToBitmap(mDrawable));
			setBackgroundDrawable(null);
		}
		mPaint=new Paint();

		setOnClickListener(this);

	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		mHeight=mWidth=mScreenWidth<mScreenHeight?mScreenWidth/3:mScreenHeight/3;
	}

	public PhotoImageView(Context context, AttributeSet attrs) {
		this(context, attrs,0);
		// TODO Auto-generated constructor stub
	}

	public PhotoImageView(Context context) {
		this(context,null);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值