柚子快報(bào)激活碼778899分享:wpf放大鏡
柚子快報(bào)激活碼778899分享:wpf放大鏡
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; 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 ControlStudy { ? ? ///
? ? ? ? private double Zoom = 1.0d;
? ? ? ? public bool ImgVisZoom ? ? ? ? { ? ? ? ? ? ? get { return (bool)GetValue(ImgVisZoomProperty); } ? ? ? ? ? ? set { SetValue(ImgVisZoomProperty, value); } ? ? ? ? }
? ? ? ? // Using a DependencyProperty as the backing store for ImgVisZoom. ?This enables animation, styling, binding, etc... ? ? ? ? public static readonly DependencyProperty ImgVisZoomProperty = ? ? ? ? ? ? DependencyProperty.Register("ImgVisZoom", typeof(bool), typeof(Magnifier), new PropertyMetadata(false));
? ? ? ? public BitmapSource ImgSource ? ? ? ? { ? ? ? ? ? ? get { return (BitmapSource)GetValue(ImgSourceProperty); } ? ? ? ? ? ? set { SetValue(ImgSourceProperty, value); } ? ? ? ? }
? ? ? ? // Using a DependencyProperty as the backing store for bitmapSource. ?This enables animation, styling, binding, etc... ? ? ? ? public static readonly DependencyProperty ImgSourceProperty = ? ? ? ? ? ? DependencyProperty.Register("ImgSource", typeof(BitmapSource), typeof(Magnifier));
? ? ? ? private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) ? ? ? ? { ? ? ? ? ? ? Zoom = 1.0f; ? ? ? ? ? ? ImgVisZoom = false; ? ? ? ? }
? ? ? ? private void Grid_MouseMove(object sender, MouseEventArgs e) ? ? ? ? { ? ? ? ? ? ? if (!ImgVisZoom) return; ? ? ? ? ? ? double Zwidth = ImgSource.Width / ActualWidth; ? ? ? ? ? ? double Zheight = ImgSource.Height / ActualHeight; ? ? ? ? ? ? System.Windows.Point point = Mouse.GetPosition(gridMagnifier); ? ? ? ? ? ? ellipse.Margin = new Thickness ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Left = point.X - ellipse.Width / 2, ? ? ? ? ? ? ? ? Top = point.Y - ellipse.Height / 2 ? ? ? ? ? ? }; ? ? ? ? ? ? double CenterX = point.X * Zwidth; ? ? ? ? ? ? double CenterY = point.Y * Zheight; ? ? ? ? ? ? double CutWidth = ellipse.Width * Zwidth / Zoom; ? ? ? ? ? ? double CutHeight = ellipse.Height * Zheight / Zoom; ? ? ? ? ? ? Int32Rect CutRect = new Int32Rect ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Width = (int)CutWidth, ? ? ? ? ? ? ? ? Height = (int)CutHeight, ? ? ? ? ? ? ? ? X = (int)(CenterX - CutWidth / 2), ? ? ? ? ? ? ? ? Y = (int)(CenterY - CutHeight / 2) ? ? ? ? ? ? }; ? ? ? ? ? ? ImageZoom.ImageSource = ImgClipRect(CutRect); ? ? ? ? }
? ? ? ? private void Ellipse_MouseWheel(object sender, MouseWheelEventArgs e) ? ? ? ? { ? ? ? ? ? ? Zoom = Math.Round(Zoom, 2); ? ? ? ? ? ? if (e.Delta > 0 && Zoom >= 1) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Zoom += 0.2; ? ? ? ? ? ? } ? ? ? ? ? ? if (e.Delta < 0 && Zoom >= 1.1) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Zoom -= 0.2; ? ? ? ? ? ? } ? ? ? ? ? ? Grid_MouseMove(null, null); ? ? ? ? }
? ? ? ? ///
? ? ? ? ? ? int cutRectX_Temp = ImgSource.Format.BitsPerPixel * CutRect.X / 8; ? ? ? ? ? ? int cutRectWidth_Temp = ImgSource.Format.BitsPerPixel * CutRect.Width / 8;
? ? ? ? ? ? for (int row = CutRect.Y; row < CutRect.Y + CutRect.Height; row++) ? ? ? ? ? ? { ? ? ? ? ? ? ? ? //for (int col = CutRect.X; col < CutRect.X + CutRect.Width; col++) ? ? ? ? ? ? ? ? for (int col = cutRectX_Temp; col < cutRectX_Temp + cutRectWidth_Temp; col++) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? if (row < 0 || row >= ImgSource.Height || col < 0 || col >= stride) ? ? ? ? ? ? ? ? ? ? //(row < 0 || row >= ImgSource.Height || col < 0 || col >= ImgSource.Width) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ListBytes.Add(0); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? //int Index = (int)(row * ImgSource.Width + col); ? ? ? ? ? ? ? ? ? ? ? ? int Index = (int)(row * stride + col); ? ? ? ? ? ? ? ? ? ? ? ? ListBytes.Add(bufOrignal[Index]); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? IntPtr pData = Marshal.AllocHGlobal(ListBytes.Count); ? ? ? ? ? ? BitmapSource source = null; ? ? ? ? ? ? try ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Marshal.Copy(ListBytes.ToArray(), 0, pData, ListBytes.Count); ? ? ? ? ? ? ? ? string strTImgType = ImgSource.Format.ToString(); ? ? ? ? ? ? ? ? if (strTImgType.Contains("Rgb24")) ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? source = BitmapSource.Create(CutRect.Width, CutRect.Height, 0, 0, PixelFormats.Rgb24, null, pData, cutRectWidth_Temp * CutRect.Height, cutRectWidth_Temp); //bgr24 血流圖像 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? source = BitmapSource.Create(CutRect.Width, CutRect.Height, 96, 96, PixelFormats.Gray8, BitmapPalettes.Gray256, pData, CutRect.Width * CutRect.Height, CutRect.Width); //gray8 ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? catch (Exception ex) ? ? ? ? ? ? { ? ? ? ? ? ? } ? ? ? ? ? ? finally ? ? ? ? ? ? { ? ? ? ? ? ? ? ? Marshal.FreeHGlobal(pData); ? ? ? ? ? ? } ? ? ? ? ? ? return source; ? ? ? ? } ? ? } } ?
柚子快報(bào)激活碼778899分享:wpf放大鏡
文章鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。