//using System;
|
//using Android.Content;
|
//using Android.Graphics;
|
//using Android.Graphics.Drawables;
|
//using Android.OS;
|
//using Android.Util;
|
//using Android.Views;
|
|
//namespace Shared
|
//{
|
// //已经全面检查了代码
|
// /// <summary>
|
// /// Button 按键
|
// /// </summary>
|
// public class ImageView : View
|
// {
|
// /// <summary>
|
// /// 当前视图
|
// /// </summary>
|
// /// <value>The android button.</value>
|
// AndroidImageView currentButton
|
// {
|
// get
|
// {
|
// return AndroidView as AndroidImageView;
|
// }
|
// set
|
// {
|
// AndroidView = value;
|
// }
|
// }
|
|
// /// <summary>
|
// /// 构造函数
|
// /// </summary>
|
// public ImageView()
|
// {
|
// currentButton = new AndroidImageView(Application.Activity, this);
|
// }
|
|
// internal string imagePath,tempImagePath;
|
// /// <summary>
|
// /// 非选中状态的背景图路径
|
// /// </summary>
|
// /// <value>The un selected image path.</value>
|
// public string ImagePath
|
// {
|
// get
|
// {
|
// return imagePath;
|
// }
|
// set
|
// {
|
// tempImagePath = value;
|
// if(!IsCanRefresh){
|
// return;
|
// }
|
// if (imageBytes != null)
|
// {
|
// (AndroidView as AndroidImageView).SetImageDrawable(Bytes2Drawable(imageBytes));
|
// return;
|
// }
|
// if (ImagePath == value) {
|
// return;
|
// }
|
// imagePath=value;
|
// Background(value);
|
// }
|
// }
|
|
// byte[] imageBytes;
|
// public byte[] ImageBytes
|
// {
|
// get
|
// {
|
// return imageBytes;
|
// }
|
// set
|
// {
|
// imageBytes = value;
|
// ImagePath = tempImagePath;
|
// }
|
// }
|
|
// public override uint Radius
|
// {
|
// get
|
// {
|
// return base.Radius;
|
// }
|
// set
|
// {
|
// base.Radius = value;
|
// if (!IsCanRefresh && Radius == value)
|
// {
|
// return;
|
// }
|
// currentButton.Invalidate();
|
// }
|
// }
|
|
// public override void Refresh()
|
// {
|
// base.Refresh();
|
// ImagePath = tempImagePath;
|
// }
|
// }
|
// public class AndroidImageView : Android.Widget.ImageView
|
// {
|
// public override bool OnTouchEvent(MotionEvent e)
|
// {
|
// base.OnTouchEvent(e);
|
// if (view != null)
|
// {
|
// view.TouchEvent(e);
|
// }
|
// return true;
|
// }
|
|
|
// private Xfermode mXfermode = new PorterDuffXfermode(PorterDuff.Mode.DstIn);
|
// private Bitmap mMaskBitmap;
|
|
// private WeakReference<Bitmap> mWeakBitmap;
|
|
|
|
// /**
|
// * 图片的类型,圆形or圆角
|
// */
|
// private int type=TYPE_ROUND;
|
// public static int TYPE_CIRCLE = 0;
|
// public static int TYPE_ROUND = 1;
|
// /**
|
// * 圆角大小的默认值
|
// */
|
// private static int BODER_RADIUS_DEFAULT = 10;
|
|
// /**
|
// * 绘图的Paint
|
// */
|
// private Paint mBitmapPaint;
|
// /**
|
// * 圆角的半径
|
// */
|
// private int mRadius;
|
// ///**
|
// // * 3x3 矩阵,主要用于缩小放大
|
// // */
|
// //private Matrix mMatrix;
|
// ///**
|
// // * 渲染图像,使用图像为绘制图形着色
|
// // */
|
// //private BitmapShader mBitmapShader;
|
|
// ///**
|
// // * view的宽度
|
// // */
|
// private int mWidth;
|
// //private RectF mRoundRect;
|
|
// View view;
|
// public AndroidImageView(Context context, View view)
|
// : base(context)
|
// {
|
// this.view = view;
|
|
// mBitmapPaint = new Paint();
|
// mBitmapPaint.AntiAlias = true;
|
|
|
// }
|
|
// protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
// {
|
// base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
// ///**
|
// // * 如果类型是圆形,则强制改变view的宽高一致,以小值为准
|
// // */
|
// if (type == TYPE_CIRCLE)
|
// {
|
// mWidth = Math.Min(MeasuredWidth, MeasuredHeight);
|
// mRadius = mWidth / 2;
|
// SetMeasuredDimension(mWidth, mWidth);
|
// }
|
|
// }
|
|
|
|
// protected override void OnDraw(Canvas canvas)
|
// {
|
// // 在缓存中取出bitmap
|
// Bitmap bitmap = null;
|
// if (mWeakBitmap != null)
|
// {
|
// mWeakBitmap.TryGetTarget(out bitmap);
|
// }
|
// if (null == bitmap || bitmap.IsRecycled)
|
// {
|
|
// // Drawable drawable = this.Drawable;
|
// // if (drawable == null)
|
// // {
|
// // return;
|
// // }
|
|
// // Bitmap bmp = drawableToBitamp(drawable);
|
// // if (bmp == null)
|
// // {
|
// // return;
|
// // }
|
// // 拿到Drawable
|
// Drawable drawable = this.Drawable;
|
// if (drawable == null)
|
// {
|
// return;
|
// }
|
|
// // 获取drawable的宽和高
|
// int dWidth = drawable.IntrinsicWidth;
|
// int dHeight = drawable.IntrinsicHeight;
|
|
// if (drawable != null)
|
// {
|
// // 创建bitmap
|
// bitmap = Bitmap.CreateBitmap(this.Width, this.Height,
|
// Bitmap.Config.Argb8888);
|
// float scale = 1.0f;
|
// // 创建画布
|
// Canvas drawCanvas = new Canvas(bitmap);
|
// // 按照bitmap的宽高,以及view的宽高,计算缩放比例;因为设置的src宽高比例可能和imageview的宽高比例不同,这里我们不希望图片失真;
|
// if (type == TYPE_ROUND)
|
// {
|
// // 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值;
|
// scale = Math.Max(this.Width * 1.0f / dWidth, this.Height
|
// * 1.0f / dHeight);
|
|
// }
|
// else
|
// {
|
// scale = this.Width * 1.0F / Math.Min(dWidth, dHeight);
|
// }
|
// // 根据缩放比例,设置bounds,相当于缩放图片了
|
// drawable.SetBounds(0, 0, (int)(scale * dWidth),
|
// (int)(scale * dHeight));
|
// drawable.Draw(drawCanvas);
|
// if (mMaskBitmap == null || mMaskBitmap.IsRecycled)
|
// {
|
// mMaskBitmap = getBitmap();
|
// }
|
// // Draw Bitmap.
|
// mBitmapPaint.Reset();
|
// mBitmapPaint.FilterBitmap = false;
|
// mBitmapPaint.SetXfermode(mXfermode);
|
// // 绘制形状
|
// drawCanvas.DrawBitmap(mMaskBitmap, 0, 0, mBitmapPaint);
|
// mBitmapPaint.SetXfermode(null);
|
// // 将准备好的bitmap绘制出来
|
// canvas.DrawBitmap(bitmap, 0, 0, null);
|
// // bitmap缓存起来,避免每次调用onDraw,分配内存
|
// mWeakBitmap = new WeakReference<Bitmap>(bitmap);
|
// }
|
// }
|
// // 如果bitmap还存在,则直接绘制即可
|
// if (bitmap != null)
|
// {
|
// mBitmapPaint.SetXfermode(null);
|
// canvas.DrawBitmap(bitmap, 0.0f, 0.0f, mBitmapPaint);
|
// return;
|
// }
|
|
|
// }
|
|
|
|
// /**
|
// * drawable转bitmap
|
// *
|
// * @param drawable
|
// * @return
|
// */
|
// private Bitmap drawableToBitamp(Drawable drawable)
|
// {
|
// if (drawable.GetType() == typeof(BitmapDrawable))
|
// {
|
// BitmapDrawable bd = (BitmapDrawable)drawable;
|
// return bd.Bitmap;
|
// }
|
// int w = drawable.IntrinsicWidth;
|
// int h = drawable.IntrinsicHeight;
|
// if (w <= 0 || h <= 0)
|
// {
|
// return null;
|
// }
|
// Bitmap bitmap = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
|
// Canvas canvas = new Canvas(bitmap);
|
// drawable.SetBounds(0, 0, w, h);
|
// drawable.Draw(canvas);
|
// return bitmap;
|
// }
|
|
|
// public override void Invalidate()
|
// {
|
// mWeakBitmap = null;
|
// if (mMaskBitmap != null)
|
// {
|
// mMaskBitmap.Recycle();
|
// mMaskBitmap = null;
|
// }
|
// base.Invalidate();
|
// }
|
|
|
// /**
|
// * 绘制形状
|
// *
|
// * @return
|
// */
|
// public Bitmap getBitmap()
|
// {
|
// Bitmap bitmap = Bitmap.CreateBitmap(this.Width, this.Height,
|
// Bitmap.Config.Argb8888);
|
// Canvas canvas = new Canvas(bitmap);
|
// Paint paint = new Paint(PaintFlags.AntiAlias);
|
// paint.Color = Android.Graphics.Color.Black;
|
|
// if (type == TYPE_ROUND)
|
// {
|
// RectF mRoundRect = new RectF(0, 0, this.Width, this.Height);
|
// //canvas.DrawRoundRect(new RectF(0, 0, this.Width, this.Height),
|
// // mRadius, mRadius, paint);
|
|
// if (!view.IsSetAloneRadius)
|
// {
|
// canvas.DrawRoundRect(mRoundRect, view.Radius, view.Radius,
|
// mBitmapPaint);
|
// }
|
// else
|
// {
|
// canvas.DrawRoundRect(mRoundRect, view.mAloneRadius, view.mAloneRadius,
|
// mBitmapPaint);
|
// if ((view.mRadiusId & 1) == 0)
|
// {
|
// canvas.DrawRect(0, 0, view.mAloneRadius, view.mAloneRadius, mBitmapPaint);
|
// }
|
|
// if ((view.mRadiusId >> 1 & 1) == 0)
|
// {
|
// canvas.DrawRect(mRoundRect.Right - view.mAloneRadius, 0, mRoundRect.Right, view.mAloneRadius, mBitmapPaint);
|
// }
|
|
// if ((view.mRadiusId >> 2 & 1) == 0)
|
// {
|
// canvas.DrawRect(0, mRoundRect.Bottom - view.mAloneRadius, view.mAloneRadius, mRoundRect.Bottom, mBitmapPaint);
|
// }
|
|
// if ((view.mRadiusId >> 3 & 1) == 0)
|
// {
|
// canvas.DrawRect(mRoundRect.Right - view.mAloneRadius, mRoundRect.Bottom - view.mAloneRadius, mRoundRect.Right, mRoundRect.Bottom, mBitmapPaint);
|
// }
|
|
// }
|
// }
|
// else
|
// {
|
// canvas.DrawCircle(this.Width / 2, this.Width / 2, this.Width / 2,
|
// paint);
|
// }
|
|
// return bitmap;
|
// }
|
|
|
// public int dp2px(int dpVal)
|
// {
|
// return (int)TypedValue.ApplyDimension(ComplexUnitType.Dip,
|
// dpVal, Resources.DisplayMetrics);
|
// }
|
// }
|
//}
|