wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
//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);
//        }
//    }
//}