private void ShowSelectedPicture(string path)
{
FileStream fs = File.OpenRead(path); //OpenRead
int filelength = ;
filelength = (int)fs.Length; //获得文件长度
Byte[] image = new Byte[filelength]; //建立一个字节数组
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource =new MemoryStream(image );
bitmapImage.EndInit();
var pictureWindow = new PictureWindow();//自己创建的窗口
pictureWindow.myImage.Source = bitmapImage;//myImage窗口中的图片空间
//pictureWindow.myImage.Width = bitmapImage.PixelWidth;
//pictureWindow.myImage.Height = bitmapImage.PixelHeight;
pictureWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
pictureWindow.ShowDialog();
}

private void MyImage_OnMouseWheel(object sender, MouseWheelEventArgs e)
    {
         double ScaleX = 0;
         double ScaleY = 0;
         double dbl_ZoomX = ((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).ScaleX;
         double dbl_ZoomY = ((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).ScaleY;
        ((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).CenterX = e.GetPosition(this.myImage).X;
        ((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).CenterY = e.GetPosition(this.myImage).Y;


if (e.Delta < 0)
       {
          ScaleX = dbl_ZoomX - 0.1 < 0.2 ? 0.1 : dbl_ZoomX - 0.1;
          ScaleY = dbl_ZoomY - 0.1 < 0.2 ? 0.1 : dbl_ZoomY - 0.1;
       }
     else if (e.Delta > 0)
     {
        ScaleX = dbl_ZoomX + 0.1 > 10.0 ? 10.0 : dbl_ZoomX + 0.1;
        ScaleY = dbl_ZoomY + 0.1 > 10.0 ? 10.0 : dbl_ZoomY + 0.1;
     }


((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).ScaleX = ScaleX;
       ((ScaleTransform)(((TransformGroup)(((UIElement)(this.myImage)).RenderTransform)).Children[0])).ScaleY = ScaleY;
    }

 

C# 上传图片

 private void UploadImage(string Path)
{
FileStream fullfs;
string pictureName = GetPictureName();
string pictureFullPath = storePath;// GetPicturePath(rtdto.BusinessIndex, rtdto.ProviderIndex);
string pictureFullName = pictureFullPath + @"\" + pictureName;
fullfs = new FileStream(pictureFullName, FileMode.Create);
BinaryWriter fullbw = new BinaryWriter(fullfs);
fullbw.Write(pidto.PictureData);
fullbw.Close();
fullfs.Close();
}
private string GetPicturePath(int businessindex, int providerindex)
{
string currentPath = AppDomain.CurrentDomain.BaseDirectory + @"\Image";
if (!System.IO.Directory.Exists(currentPath))
{
try
{
System.IO.Directory.CreateDirectory(currentPath);
}
catch
{
currentPath = AppDomain.CurrentDomain.BaseDirectory;//创建目录失败,存入根目录中
}
}
string filePath = currentPath + @"\" + businessindex + "_" + providerindex;
if (!System.IO.Directory.Exists(filePath))
{
try
{
System.IO.Directory.CreateDirectory(filePath);
}
catch
{
filePath = currentPath;//创建目录失败,存入根目录中
} }
return filePath;
}
private string GetPictureName()
{
string imageGuid = Guid.NewGuid().ToString() + ".jpg";
return imageGuid;
}

窗口页面代码

<Window x:Class="App.Modules.PictureWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uiControls="clr-namespace:Allegion.Components.UIControls;assembly=Allegion.Components.UIControls"
Title="PictureWindow"> <ScrollViewer x:Name="scrollViewer"
HorizontalScrollBarVisibility="Auto"
MouseWheel="ScrollViewer_OnMouseWheel"
VerticalScrollBarVisibility="Auto"> <Image Name="myImage" MouseWheel="MyImage_OnMouseWheel">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="" ScaleY="" />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</Image.RenderTransform>
</Image>
</ScrollViewer>
</Window>

最新文章

  1. 实验验证redis的快照和AOF
  2. 文件上传限制大小 dotnet/C#
  3. Linux学习之八——利用变量
  4. C# 打印异常
  5. [Guava源码分析] Preconditions 前置条件
  6. 关于异常的疑难解答:System.Runtime.InteropServices.COMException
  7. 【39】FlexboxLayout使用介绍
  8. python学习笔记(十 三)、网络编程
  9. java线程学习之synchronized关键字
  10. ROS使用FLIR品牌的相机
  11. Android 官方DEMO - ActionBarCompat-Basic
  12. 如何用Caffe训练自己的网络-探索与试验
  13. Reading | 《Linux就该这么学》
  14. 关于 SqlParameter 必须知道的!
  15. HTML5学习笔记(九):选择器详解
  16. 455. Assign Cookies
  17. Unity编辑器扩展chapter1
  18. Web前端学习笔记之jQuery基础
  19. 【转】C语言中DEFINE简介及多行宏定义
  20. MyISAM和InnoDB的行格式ROW_FORMAT

热门文章

  1. Web服务器压力测试一例
  2. Android学习之Notification
  3. MRP工作台任务下达之x组织屏蔽全部发放功能
  4. FPGrowth算法原理
  5. hibernate异常
  6. 在eclipse上提交任务到集群执行
  7. boost信号量 boost::interprocess::interprocess_semaphore的用法
  8. memcached的安装和linux下memcached服务自启动的配置
  9. php简单对象与数组的转换
  10. JQUERY选择和操作DOM元素(利用正则表达式的方法匹配字符串中的一部分)