C# 弹出窗口查看图片以及上传图片

您所在的位置:网站首页 如何缩小弹窗大小的窗口显示图片 C# 弹出窗口查看图片以及上传图片

C# 弹出窗口查看图片以及上传图片

2024-07-10 19:25| 来源: 网络整理| 查看: 265

private void ShowSelectedPicture(string path) { FileStream fs = File.OpenRead(path); //OpenRead int filelength = 0; 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;    }

 


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3