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

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;

  1.  

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;
     }

  1.  

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

  1.  

C# 上传图片

  1. private void UploadImage(string Path)
  2. {
  3. FileStream fullfs;
  4. string pictureName = GetPictureName();
  5. string pictureFullPath = storePath;// GetPicturePath(rtdto.BusinessIndex, rtdto.ProviderIndex);
  6. string pictureFullName = pictureFullPath + @"\" + pictureName;
  7. fullfs = new FileStream(pictureFullName, FileMode.Create);
  8. BinaryWriter fullbw = new BinaryWriter(fullfs);
  9. fullbw.Write(pidto.PictureData);
  10. fullbw.Close();
  11. fullfs.Close();
  12. }
  13. private string GetPicturePath(int businessindex, int providerindex)
  14. {
  15. string currentPath = AppDomain.CurrentDomain.BaseDirectory + @"\Image";
  16. if (!System.IO.Directory.Exists(currentPath))
  17. {
  18. try
  19. {
  20. System.IO.Directory.CreateDirectory(currentPath);
  21. }
  22. catch
  23. {
  24. currentPath = AppDomain.CurrentDomain.BaseDirectory;//创建目录失败,存入根目录中
  25. }
  26. }
  27. string filePath = currentPath + @"\" + businessindex + "_" + providerindex;
  28. if (!System.IO.Directory.Exists(filePath))
  29. {
  30. try
  31. {
  32. System.IO.Directory.CreateDirectory(filePath);
  33. }
  34. catch
  35. {
  36. filePath = currentPath;//创建目录失败,存入根目录中
  37. }
  38.  
  39. }
  40. return filePath;
  41. }
  42. private string GetPictureName()
  43. {
  44. string imageGuid = Guid.NewGuid().ToString() + ".jpg";
  45. return imageGuid;
  46. }

窗口页面代码

  1. <Window x:Class="App.Modules.PictureWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:uiControls="clr-namespace:Allegion.Components.UIControls;assembly=Allegion.Components.UIControls"
  5. Title="PictureWindow">
  6.  
  7. <ScrollViewer x:Name="scrollViewer"
  8. HorizontalScrollBarVisibility="Auto"
  9. MouseWheel="ScrollViewer_OnMouseWheel"
  10. VerticalScrollBarVisibility="Auto">
  11.  
  12. <Image Name="myImage" MouseWheel="MyImage_OnMouseWheel">
  13. <Image.RenderTransform>
  14. <TransformGroup>
  15. <ScaleTransform ScaleX="" ScaleY="" />
  16. <SkewTransform />
  17. <RotateTransform />
  18. <TranslateTransform />
  19. </TransformGroup>
  20. </Image.RenderTransform>
  21. </Image>
  22. </ScrollViewer>
  23. </Window>

C# 弹出窗口查看图片以及上传图片的更多相关文章

  1. jQuery弹出窗口浏览图片

    效果预览:http://keleyi.com/keleyi/phtml/jqtexiao/3.htm HTML文件代码: <!DOCTYPE HTML> <html> < ...

  2. chrome浏览器上传图片反应很慢,延迟很久才弹出窗口

    chrome浏览器上传图片反应很慢,延迟很久才弹出窗口 一个上传图片的控件,点击按钮上传图片,用chrome(谷歌浏览器)时,点击按钮后,要等好几秒才弹出文件选择窗口 可以试一下,把网络断开,这个问题 ...

  3. jQuery弹出窗口完整代码

    jQuery弹出窗口完整代码 效果体验:http://keleyi.com/keleyi/phtml/jqtexiao/1.htm 1 <!DOCTYPE html PUBLIC "- ...

  4. jQuery插件---轻量级的弹出窗口wBox

    Box Demo wBox——轻量级的弹出窗口jQuery插件,基于jQuery1.4.2开发,主要实现弹出框的效果,并且加入了很多有趣的功能,比如可img灯箱效果,callback函数,显示隐藏层, ...

  5. OAF_开发系列08_实现OAF通过Popup参数式弹出窗口(案例)

    20150711 Created By BaoXinjian

  6. ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件

    原文:ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件 先看效果图,然后上代码: <UserControl x:Class= ...

  7. js弹出窗口的学习和使用

    Thickbox Thickbox是基于Jquery的,因此使用Thickbox需要下面四个文件: Thickbox.js----Thickbox主文件 CSS文件----Thickbox.css 最 ...

  8. [selenium webdriver Java]处理弹出窗口

    Selenium WebDriver测试弹出窗口,包括识别弹出窗口,将driver转到新的窗口,在新的串钩中执行而是步骤,然后再转换到最初的窗口. 通过名称(name)识别和处理: Selenium ...

  9. Win8 弹出窗口不在最前端的解决方法

    Win8系统的使用者有很多会遇到弹出窗口不在最前端的情况(自动隐藏,点下页面又出来),比如另存为的时候 ,或是登录路由器时弹出的登录框时. 引起这个异常的原因是与系统输入法冲突引起,但又不可能不用第三 ...

随机推荐

  1. 奇妙的算法之LCS妙解

    LCS算法妙解 LCS问题简述:最长公共子序列 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则S 称为已知序列的最长公共子序列. LCS问题的分支:最长公共子串 ...

  2. hunnu11543:小明的烦恼——分糖果

    Problem description   小明在班里一直是个非常公正的孩子.这点同学和老师都非常清楚,这不,老师每周都会从家里带来一些糖果.然后叫小明把糖果分给其它小朋友,但这个班里的同学都有一个非 ...

  3. 要删除共享的初始登陆名 cmd下输入net use * /delete

    要删除共享的初始登陆名 cmd下输入net use *  /delete

  4. barManager.Menu(barSubItem)

    DevExpress 的帮助文档是在太缺乏了,他自己的帮助只有简单描述,没有样例,而它的网站上的在线帮助只有利用它的设计器设计的ToolBar.PopupMenu ,没有利用代码开发的.虽然要利用代码 ...

  5. IE6、7下获得offset值跟其他浏览器不一样问题

    大家都知道,offset是元素的位置坐标,那位置坐标又和文档流有关系.如果position默认不设置的话,其值是static.static是个什么东东呢?下面我详细介绍一下: 语法: position ...

  6. 关于C语言指针几个容易混淆的概念

    前言: 大多数学习过C/C++或者正在学习的同学在对指针概念把握时,总是感觉不太明了,小弟我也不例外啊,于是翻开资料复习整理一下,并把自己的学习心得拿出来供大家分享,讨论. 基本概念掠过,主要来探讨一 ...

  7. css画图形

    博客:  史上最强大的40多个纯cs图形 问题:看了上面的博客思考简单的三角行是怎么形成的? #triangle-up { width: 0; height: 0; border-left: 50px ...

  8. zoj1108 FatMouse's Speed

    给你每个物体两个参数,求最长的链要求第一个参数递增,第二个参数递减,要求输出任意最长路径. 首先第一反应根据第二个参数排个序,然后不就是最长上升子序列的问题吗? O(nlogn)的复杂度,当然这样可以 ...

  9. poj 3411 Paid Roads

    题意:有m条路,n座城市,走这些路是要付费的,每条路由两种付费方案,设一条路两端是a,b,如果走完这条路在b点付费的话,应付r,如果走这条路之前在c点付费的话,应付p,求从1端点走到n端点的最小费用. ...

  10. 关于google CDN 在中国访问不了的解决办法

    因原网站的script部分使用了google CDN,导致在中国看不了跟google相关的所有东西 解决方法: 得把google CDN 连接改成其他公司的CDN 例: 修改前:<script ...