年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
5.4 KiB

6 months ago
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using Kingo.ImageViewForWebSocket;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace Kingo.Plugin.General.View
{
/// <summary>
/// UCShowImage.xaml 的交互逻辑
/// </summary>
public partial class UCShowImage : BaseWindow
{
private List<AttachEntity> attachEntities = null;
public string _imagePath { get; set; }
public UCShowImage(string imagePath = "", List<AttachEntity> ImgList = null)
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;//添加这句
if (!string.IsNullOrEmpty(imagePath))
{
_imagePath = imagePath;
LoadImage(imagePath);
}
if (ImgList != null)
attachEntities = ImgList;
}
private BitmapImage _image;
public BitmapImage Image
{
get { return _image; }
set
{
if (_image != value)
{
_image = value;
//OnPropertyChanged(nameof(Image));
}
}
}
public void LoadImage(string imagePath)
{
try
{
// 从图片路径加载图像数据
byte[] imageData = File.ReadAllBytes(imagePath);
// 将字节数据转换为BitmapImage
using (MemoryStream memoryStream = new MemoryStream(imageData))
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memoryStream;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
// 设置Image属性值
Image = bitmapImage;
imgInfo.Source = Image;
}
}
catch (System.Exception ex)
{
LogAPI.Debug("LoadImage异常:" + ex.Message);
LogAPI.Debug("LoadImage异常:" + ex.StackTrace);
}
}
#region 上一张
private void Prev_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (attachEntities != null && !string.IsNullOrEmpty(_imagePath))
{
int attIndex = attachEntities.FindIndex(x => x.AttachLocationPath == _imagePath);
if (attIndex <= 0) return;
attIndex = attIndex - 1;
var attachEntitie = attachEntities[attIndex];
if (attachEntitie != null)
{
LoadImage(attachEntitie.AttachLocationPath);
_imagePath = attachEntitie.AttachLocationPath;
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "Prev" });
}
}
}
catch (System.Exception ex)
{
LogAPI.Debug("LoadImage异常:" + ex.Message);
LogAPI.Debug("LoadImage异常:" + ex.StackTrace);
}
}
#endregion
#region 下一张
private void Next_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (attachEntities != null && !string.IsNullOrEmpty(_imagePath))
{
int attIndex = attachEntities.FindIndex(x => x.AttachLocationPath == _imagePath);
if (attIndex >= attachEntities.Count - 1) return;
attIndex = attIndex + 1;
var attachEntitie = attachEntities[attIndex];
if (attachEntitie != null)
{
LoadImage(attachEntitie.AttachLocationPath);
_imagePath = attachEntitie.AttachLocationPath;
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "Next" });
}
}
}
catch (System.Exception ex)
{
LogAPI.Debug("LoadImage异常:" + ex.Message);
LogAPI.Debug("LoadImage异常:" + ex.StackTrace);
}
}
#endregion
Point _pressedPosition;
bool _isDragMoved = false;
private void BaseWindow_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
_pressedPosition = e.GetPosition(this);
}
private void BaseWindow_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Pressed && _pressedPosition != e.GetPosition(this))
{
_isDragMoved = true;
DragMove();
}
}
private void BaseWindow_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (_isDragMoved)
{
_isDragMoved = false;
e.Handled = true;
}
}
}
}