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.

185 lines
6.7 KiB

using Container.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Container.Win
{
/// <summary>
/// UCImageText.xaml 的交互逻辑
/// </summary>
public partial class UCImageText : UserControl
{
App app = ((App)System.Windows.Application.Current);
public UCImageText(string img="", string text = "", string ScreenMatch = "")
{
InitializeComponent();
if (!string.IsNullOrEmpty(img)) {
try
{
//this.UCText.Text = text;
////Uri uri = new Uri(img, UriKind.RelativeOrAbsolute);
////ImageBrush ib = new ImageBrush();
////ib.ImageSource = new BitmapImage(uri);
////this.Img.Source = ib.ImageSource;
//BinaryReader binReader = new BinaryReader(File.Open(img, FileMode.Open));
//FileInfo fileInfo = new FileInfo(img);
//byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
//binReader.Close();
//// 将图片字节赋值给BitmapImage
//BitmapImage bitmap = new BitmapImage();
//bitmap.BeginInit();
//bitmap.StreamSource = new MemoryStream(bytes);
//bitmap.EndInit();
//// 最后给Image控件赋值
//this.Img.Source = bitmap;
//this.Img.Width = SystemParameters.PrimaryScreenWidth;
//this.Img.Height = SystemParameters.PrimaryScreenHeight;
//if (!string.IsNullOrEmpty(ScreenMatch))
//{
// if (ScreenMatch.Trim().Equals("拉伸"))
// {
// this.Img.Stretch = Stretch.Fill;
// }
// else if (ScreenMatch.Trim().Equals("适应"))
// {
// this.Img.Stretch = Stretch.Uniform;
// }
// else if (ScreenMatch.Trim().Equals("填充"))
// {
// this.Img.Stretch = Stretch.UniformToFill;
// }
// else if (ScreenMatch.Trim().Equals("居中"))
// {
// this.Img.Stretch = Stretch.None;
// }
//}
this.UCText.Text = text;
Uri uri = new Uri(img, UriKind.RelativeOrAbsolute);
ImageBrush ib = new ImageBrush();
Class_Log log = new Class_Log();
log.WriteLogFile(img, "ucimage");
ib.ImageSource = new BitmapImage(uri);
this.Img.Source = ib.ImageSource;
this.Img.Width = app.ScreenWidth;
this.Img.Height = app.ScreenHeight;
if (!string.IsNullOrEmpty(ScreenMatch))
{
if (ScreenMatch.Trim().Equals("拉伸"))
{
this.Img.Stretch = Stretch.Fill;
}
else if (ScreenMatch.Trim().Equals("适应"))
{
this.Img.Stretch = Stretch.Uniform;
}
else if (ScreenMatch.Trim().Equals("填充"))
{
this.Img.Stretch = Stretch.UniformToFill;
}
else if (ScreenMatch.Trim().Equals("居中"))
{
this.Img.Stretch = Stretch.None;
}
else
{
this.Img.Stretch = Stretch.Uniform;
}
}
}
catch (Exception ex)
{
Class_Log log = new Class_Log();
log.WriteLogFile(ex.ToString(), "UCImageError");
}
}
}
public void LoadData(double width, double height, string img, string text = "", string ScreenMatch = "")
{
try
{
this.Width = width;
this.Height = height;
Uri uri = new Uri(img, UriKind.RelativeOrAbsolute);
ImageBrush ib = new ImageBrush();
Class_Log log = new Class_Log();
log.WriteLogFile(img, "ucimage");
if (File.Exists(img))
{
ib.ImageSource = new BitmapImage(uri);
ib.Freeze();
this.Img.Source = ib.ImageSource;
this.Img.Width = width;
this.Img.Height = height;
if (!string.IsNullOrEmpty(ScreenMatch))
{
if (ScreenMatch.Trim().Equals("拉伸"))
{
this.Img.Stretch = Stretch.Fill;
}
else if (ScreenMatch.Trim().Equals("适应"))
{
this.Img.Stretch = Stretch.Uniform;
}
else if (ScreenMatch.Trim().Equals("填充"))
{
this.Img.Stretch = Stretch.UniformToFill;
}
else if (ScreenMatch.Trim().Equals("居中"))
{
this.Img.Stretch = Stretch.None;
}
else
{
this.Img.Stretch = Stretch.Uniform;
}
}
else
{
this.Img.Stretch = Stretch.Uniform;
}
}
else
{
log.WriteLogFile(img + "不存在", "UCImageError");
}
}
catch (Exception ex)
{
Class_Log log = new Class_Log();
log.WriteLogFile(ex.ToString(), "UCImageError");
}
}
}
}