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.
 
 
 
 

116 lines
4.0 KiB

using PCScreenSavers.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 PCScreenSavers.Win
{
/// <summary>
/// UCImageText.xaml 的交互逻辑
/// </summary>
public partial class UCImageText : UserControl
{
public UCImageText(string img, string text = "", string ScreenMatch = "")
{
InitializeComponent();
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();
ib.ImageSource = new BitmapImage(uri);
this.Img.Source = ib.ImageSource;
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;
}
else {
this.Img.Stretch = Stretch.Uniform;
}
}
}
catch (Exception ex)
{
Class_Log log = new Class_Log();
log.WriteLogFile(ex.ToString(),"UCImageError");
}
}
}
}