资源简介
xamarin.forms, xamarin.forms,xamarin.forms,xamarin.forms,xamarin.forms,xamarin.formsxamarin.forms,
xamarin.forms, xamarin.forms,xamarin.forms,xamarin.forms,xamarin.forms,xamarin.formsxamarin.forms
代码片段和文件信息
using Android.Views;
using Android.Graphics;
using Android.Content;
using System;
namespace Signature.Droid
{
public class DrawView : View
{
public DrawView(Context context)
: base(context)
{
Start();
}
public Color CurrentLineColor { get; set; }
public String ImageFilePath { get; set; }
public float PenWidth { get; set; }
private Path DrawPath;
private Paint DrawPaint;
private Paint CanvasPaint;
private Canvas DrawCanvas;
private Bitmap CanvasBitmap;
private int w h;
private Bitmap _image = null;
private void Start()
{
CurrentLineColor = Color.Black;
PenWidth = 5.0f;
DrawPath = new Path();
DrawPaint = new Paint
{
Color = CurrentLineColor
AntiAlias = true
StrokeWidth = PenWidth
};
DrawPaint.Setstyle(Paint.style.Stroke);
DrawPaint.StrokeJoin = Paint.Join.Round;
DrawPaint.StrokeCap = Paint.Cap.Round;
CanvasPaint = new Paint
{
Dither = true
};
}
public void Clear()
{
try
{
DrawPath = new Path();
CanvasBitmap = Bitmap.CreateBitmap(w h Bitmap.Config.Argb8888);
DrawCanvas = new Canvas(CanvasBitmap);
}
catch (Exception e)
{
}
Invalidate();
}
protected override void OnSizeChanged(int w int h int oldw int oldh)
{
base.OnSizeChanged(w h oldw oldh);
if (w > 0 && h > 0)
{
try
{
CanvasBitmap = Bitmap.CreateBitmap(w h Bitmap.Config.Argb8888);
DrawCanvas = new Canvas(CanvasBitmap);
this.w = w;
this.h = h;
}
catch(Exception ex)
{
}
}
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
DrawPaint.Color = CurrentLineColor;
DrawPaint.StrokeWidth = PenWidth;
canvas.DrawBitmap(CanvasBitmap 0 0 CanvasPaint);
canvas.DrawPath(DrawPath DrawPaint);
}
public override bool OnTouchEvent(MotionEvent e)
{
var touchX = e.GetX();
var touchY = e.GetY();
switch (e.Action)
{
case MotionEventActions.Down:
DrawPath.MoveTo(touchX touchY);
break;
case MotionEventActions.Move:
DrawPath.LineTo(touchX touchY);
break;
case MotionEventActions.Up:
DrawCanvas.DrawPath(DrawPath DrawPaint);
DrawPath.Reset();
break;
default:
return false;
}
Invalidate();
return true;
}
public void LoadImageFromFile()
{
if (ImageFilePath != null && ImageFilePath != ““)
{
_image = BitmapFactory.DecodeFile(ImageFilePath);
}
}
public Bitmap GetImageFromView()
{
Bitmap tempBitmap = null;
try
{
tempBitmap = Bitmap.CreateBitmap(w h Bitmap.Config.Argb8888);
DrawCanvas = new Canvas(tempBitmap);
if (_image != null)
{
DrawPaint.Setstyle(Paint.style.Fill);
DrawPaint.Color = Color.White;
DrawCanvas.DrawRect(new Rect(0 0 w h) DrawPaint);
float scaleX = (float)_image.Width / w;
float scaleY = (float)_image.Height / h;
Rect outRect = new Rect();
int outWidth outHeight;
if (scaleX > scaleY
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-03-18 15:25 Signature\
目录 0 2016-03-18 15:59 Signature\.git\
文件 144 2016-03-18 12:52 Signature\.git\config
文件 73 2016-03-18 12:52 Signature\.git\desc
文件 23 2016-03-18 12:52 Signature\.git\HEAD
目录 0 2016-04-05 23:54 Signature\.git\hooks\
文件 177 2016-03-18 12:52 Signature\.git\hooks\README.sample
文件 3536 2016-03-18 15:59 Signature\.git\index
目录 0 2016-04-05 23:54 Signature\.git\info\
文件 113 2016-03-18 12:52 Signature\.git\info\exclude
目录 0 2016-03-18 15:59 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 149 2016-03-18 12:56 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 119 2016-03-18 13:13 Signature\.git\ob
目录 0 2016-03-18 12:52 Signature\.git\ob
文件 2010 2016-03-18 12:52 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 766 2016-03-18 12:52 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 1201 2016-03-18 12:52 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 210 2016-03-18 12:52 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 104 2016-03-18 13:16 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 251 2016-03-18 12:52 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 97 2016-03-18 12:57 Signature\.git\ob
目录 0 2016-04-05 23:54 Signature\.git\ob
文件 1385 2016-03-18 12:52 Signature\.git\ob
............此处省略279个文件信息
评论
共有 条评论