using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 一个能够进行裁剪图片的控件
///
public class CutPictureControl : ImageView
{
#region ■ 变量声明___________________________
///
/// 选择图片的事件
///
public Action SelectPictrueEvent = null;
#endregion
#region ■ 初始化_____________________________
///
/// 一个能够进行裁剪图片的控件
///
/// 保存裁剪图片的文件名(全路径)
/// 宽度
/// 高度
/// 是否计算真实值
public CutPictureControl(string saveFullFileName, int i_Width, int i_Height, bool real = true)
{
if (real == true)
{
i_Width = Application.GetMinRealAverage(i_Width);
i_Height = Application.GetMinRealAverage(i_Height);
}
this.Height = i_Height;
this.Width = i_Width;
this.MouseUpEventHandler += (sender, e) =>
{
//显示获取图片来源的方式
this.ShowGetPictrueWayMenu(saveFullFileName);
};
}
#endregion
#region ■ 显示获取图片来源的方式_____________
///
/// 显示获取图片来源的方式
///
/// 保存裁剪图片的文件名(全路径)
private void ShowGetPictrueWayMenu(string saveFullFileName)
{
//自定义菜单控件
var form = new PictrueWayMenuControl();
form.AddForm();
form.SelectPictrueEvent += (selectPic) =>
{
try
{
if (System.IO.File.Exists(saveFullFileName) == true)
{
System.IO.File.Delete(saveFullFileName);
}
//移动文件
System.IO.File.Move(selectPic, saveFullFileName);
//改变图片
this.ImagePath = saveFullFileName;
//调用回调函数
this.SelectPictrueEvent?.Invoke(saveFullFileName);
}
catch (Exception ex)
{
//出现未知错误
var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
alert.Show();
//Log
HdlLogLogic.Current.WriteLog(ex);
}
};
}
#endregion
#region ■ 控件摧毁___________________________
///
/// 控件摧毁
///
public override void RemoveFromParent()
{
this.SelectPictrueEvent = null;
base.RemoveFromParent();
}
#endregion
#region ■ 菜单控件___________________________
///
/// 菜单控件
///
private class PictrueWayMenuControl : DialogCommonForm
{
#region ■ 变量声明___________________________
///
/// 选择图片的事件
///
public Action SelectPictrueEvent = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
var frameBack1 = new FrameLayoutControl();
frameBack1.UseClickStatu = false;
frameBack1.Y = Application.GetRealHeight(1420);
frameBack1.Gravity = Gravity.CenterHorizontal;
frameBack1.RadiusEx = 12;
frameBack1.Width = Application.GetRealWidth(1034);
frameBack1.Height = Application.GetRealHeight(300);
frameBack1.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack1);
//拍照
var btnTakePhone = new NormalViewControl(900, 156, true);
btnTakePhone.Gravity = Gravity.CenterHorizontal;
btnTakePhone.TextAlignment = TextAlignment.Center;
btnTakePhone.TextColor = 0xff0075ff;
btnTakePhone.TextSize = 17;
btnTakePhone.TextID = R.MyInternationalizationString.uTakePictrue;
frameBack1.AddChidren(btnTakePhone, ChidrenBindMode.NotBind);
btnTakePhone.ButtonClickEvent += (sender, e) =>
{
//关闭界面
this.CloseForm();
//通过相机拍照裁剪
CropImage.TakePicture((imagePath) =>
{
if (string.IsNullOrEmpty(imagePath) == false)
{
//调用回调函数
this.SelectPictrueEvent(imagePath);
}
this.SelectPictrueEvent = null;
}, "HdlPicture");
};
//线
var btnLine = new NormalViewControl(frameBack1.Width, ControlCommonResourse.BottomLineHeight, false);
btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
btnLine.Y = btnTakePhone.Bottom;
frameBack1.AddChidren(btnLine, ChidrenBindMode.NotBind);
//从相册中选择
var btnAlbum = new NormalViewControl(900, 144, true);
btnAlbum.Y = btnLine.Bottom;
btnAlbum.Gravity = Gravity.CenterHorizontal;
btnAlbum.TextAlignment = TextAlignment.Center;
btnAlbum.TextColor = 0xff0075ff;
btnAlbum.TextSize = 17;
btnAlbum.TextID = R.MyInternationalizationString.uGetPictrueFromAlbum;
frameBack1.AddChidren(btnAlbum, ChidrenBindMode.NotBind);
btnAlbum.ButtonClickEvent += (sender, e) =>
{
//关闭界面
this.CloseForm();
//从相册选择图片裁剪
CropImage.SelectPicture((imagePath) =>
{
if (string.IsNullOrEmpty(imagePath) == false)
{
//调用回调函数
this.SelectPictrueEvent(imagePath);
}
this.SelectPictrueEvent = null;
}, "HdlPicture");
};
var frameBack2 = new FrameLayoutControl();
frameBack2.UseClickStatu = false;
frameBack2.Y = frameBack1.Bottom + Application.GetRealHeight(23);
frameBack2.Gravity = Gravity.CenterHorizontal;
frameBack2.RadiusEx = 12;
frameBack2.Width = Application.GetRealWidth(1034);
frameBack2.Height = Application.GetRealHeight(156);
frameBack2.BackgroundColor = UserCenterColor.Current.White;
bodyFrameLayout.AddChidren(frameBack2);
//取消
var btnCancel = new NormalViewControl(900, 156, true);
btnCancel.Gravity = Gravity.CenterHorizontal;
btnCancel.TextAlignment = TextAlignment.Center;
btnCancel.TextColor = 0xff0075ff;
btnCancel.TextSize = 17;
btnCancel.TextID = R.MyInternationalizationString.uCancel;
frameBack2.AddChidren(btnCancel, ChidrenBindMode.NotBind);
btnCancel.ButtonClickEvent += (sender, e) =>
{
this.SelectPictrueEvent = null;
//关闭界面
this.CloseForm();
};
}
#endregion
}
#endregion
}
}