Article From:https://www.cnblogs.com/lonelyxmas/p/9689169.html
WPF divides the picture into two automatic page WpfFlipPageControl:CtrlBook Book controls.

Copyright notice: This article is an original article for bloggers, which needs to be reprinted, though reproduced. Https://blog.csdn.net/z5976749/article/details/39671691

WPF  CtrlBookUsage method:

First, add the reference: using WpfFlipPageControl;

dllName: WpfFlipPageControl.dll, download address: http://api.dllzj.com/down/WpfFlipPageControl.dll.html

Add ctrlBook control (Book Control) in Blend.

ctrlBookThe control itself is divided into two parts: if both sides are independent pictures, it is more convenient.

            Image im = new Image();		//The image of the image object control here is not the Image class of the picture.Im.Source = new BitmapImage (New Uri (@ image path)); //ImAdd resources to age controlMybook.Items.Add (IM); / / book control add Image control, also can add canvas and other controls.Im = new ImAge ();Im.Source = new BitmapImage (New Uri (@ image path));Mybook.Items.Add (IM);

So the book control has two pages, the mouse can flip through the four corners of the control, the picture control’s stretch property set to Fill better.

CtrlBookPage turning method:

myBook.AnimateToNextPage(true, 1000);  

If a picture is divided into two parts, you need a picture segmentation, the main idea is that a picture is divided into two equal parts of the picture and then added to the image control, the book control to add the image control

First, add a null to the first picture, because the book control is added from the right side by default.

myBook.Items.Add(null); //The first page of the book control is empty.

        /// <summary>
        /// Loading picture information/ / / < /summary>Private void SetBook (){MyBook.Items.Clear ();StrsPath = Directory.GetFiles (Directory.GetCurrentDirectory () + "/source"/images); / / local image path collectionMyBook.Items.Add (null); / / book control the first page is empty./ / left and rightImage containerSystem.Windows.Controls.Image imageLeft = null; //system.windows.Controls is quoted because the class name of WPF is the same, and the namespace must be declared.System.Windows.Controls.Image imageRight = nulL;System.Drawing.Bitmap bitmap = null; / / create bitmap objectSystem.Drawing.SizeSize = new System.Drawing.Size (0, 0); //size object (2 size classes, attention distinction)System.Drawing.PointPoint = new System.Drawing.Point (0, 0); //point object (2 point classes, attention distinction)IntPtr intPtr= new InTPtr (); / / / for platform specific types that indicate pointers or handles.Foreach (string path in strsPath)/ / circular addition of image resources{/ / instantiate the left and right picture control types, such as not instantiating the Image control, only modifying the S of the control.The ource attribute is myBook.Items add control to report < /span>ImageLeft = new System.Windows.Controls.IMage (); / / must re instantiate the image object.ImageRight = new System.Windows.Controls.Image ();Bitmap = new System. Drawing. Bitmap (path); create a bitmap object from which you can get its own width and height for size segmentationSize = new System. Drawing. Size (bitmap. Width / 2, bitmap. Height); the size of the picture on the left and right sides, / / because it's divided into two parts, soDivide width by 2/ / left container image segmentationPoint = new System.Drawing.Point (0, 0); / / segmentation starting point (00)System. Drawing. Bitmap imageLeftShow = getImage (path, point, size); / / Get on the left by splitting the imageBitmap object displayed/ / right container image segmentationPoint = new System.Drawing.Point (bitmap.Width /2, 0); / / the middle begins to split by half of the width of the bitmap object.System.Drawing.Bitmap imageRightShow = getImage (path, POI)NT, size);IntPtr = imageLeftShow.GetHbitmap (); / / the left bitmap type image is transformed into intPtr type./ / the left picture intPtr is transformed into imageSource type < /span>ImageLeft.Source = System.WIndows.Interop.Imaging.CreateBitmapSourceFromHBitmap (intPtr, IntPtr.Zero, Int32Rect.Empty, BitmapSiz)EOptions.FromEmptyOptions ());IntPtr = imageRightShow.GetHbitmap (); / / right picture turnInto intPtr typeImageRight.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFroMHBitmap (intPtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions ());MyBook.Items.Add (imageLeft); / / book control add image control.MyBook.Items.Add (imageRight);ImageLeft.Stretch = Stretch.Fill;ImageRight.Stretch = Stretch.Fill;}}/ / / < summary>/ / / according to the starting point point, size to cut pictures./ / / < /summary>Private System.Drawing.Bitmap getImage (string path, System.Drawing.)Point point, System.Drawing.Size size){/ / image pathSystem.Drawing.BiTMAP bitmap = new System.Drawing.Bitmap (path); / / load the original picture./ / create rectangle with initial location and size.SSystem. Drawing. Rectangle r = new System. Drawing. Rectangle (point, size); Instantiate a matrix object by location and size/ / return the image copy of the rectangle area.Bitmap = bitmap.Clone (R, System.Drawing.Imaging.PixelFormat.Undefined)/ / according to the size of the matrix, create a copy of the original bitmap.Return bitmap; returns the bitmap copy created.}

Leave a Reply

Your email address will not be published. Required fields are marked *