Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to show the center part of the icVideo box by cropping and show it to bottom part of the icVideo. here middle part of the icVideo will be the diamond's girdle part(the three lines between diamond) as here is example of the project image
Screenshot-2024-02-02-115020 hosted at ImgBB — ImgBB[^]
the height of the cropped part is okay but i want to show the center of the icVideo where currently i am getting top of the icVideo. i have tried multiple solutions but it didn't work. how do i show that center of the icVideo at bottom of the icVideo box?

What I have tried:

here i have icVideo_OverlayUpdate event

C#
private void icVideo_OverlayUpdate(object sender, ICImagingControl.OverlayUpdateEventArgs e)
        {
            try
            {
                imageToDisplay = Diamond_Steaching.Properties.Resources.Sparrow1;

                this.ob = e.overlay;
                this.CentX = this.icVideo.Width / 2;
                this.CentY = this.icVideo.Height / 2;
                this.ob.DropOutColor = System.Drawing.Color.Magenta;
                this.ob.Fill(System.Drawing.Color.Magenta);
                this.ob.Enable = true;
                this.ob.FontBackColor = this.ob.DropOutColor;
                this.ob.FontTransparent = false;
                bool bdrawgraph = true;

                

                int x0_2 = 12;
                int y0_2 = 10;
                this.ob.Font = new Font("Arial", 10f, FontStyle.Bold);
                this.ob.DrawText(System.Drawing.Color.Red, x0_2, y0_2, "Inspector v3.0.3");
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 15, "Diameter : " + GlobalManagement.Instance.objDiamond.Diameter);
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 30, "CrownAngle : " + GlobalManagement.Instance.objDiamond.CrownAngle);
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 45, "CrownHeight : " + GlobalManagement.Instance.objDiamond.CrownHeight);
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 60, "BottomAngle : " + GlobalManagement.Instance.objDiamond.BottomAngle);
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 75, "Girdle : " + GlobalManagement.Instance.objDiamond.Girdle);
                this.ob.DrawText(System.Drawing.Color.Yellow, x0_2, y0_2 + 90, "Table : " + GlobalManagement.Instance.objDiamond.Table);


                
                // Draw the image onto the overlay bitmap
                if (imageToDisplay != null)
                {
                    using (Graphics g = ob.GetGraphics())
                    {
                        int imageX = 250; // Adjust these coordinates as needed
                        int imageY = 1; // Adjust these coordinates as needed
                        int imageWidth = 60; // Adjust the width of the image
                        int imageHeight = 60; // Adjust the height of the image
                        //g.DrawImage(imageToDisplay, imageX, imageY);
                        Rectangle destinationRect = new Rectangle(imageX, imageY, imageWidth, imageHeight);
                        g.DrawImage(imageToDisplay, destinationRect);

                        x0_2 = 310; //720
                        y0_2 = 20; //480
                        this.ob.Font = new Font("Arial", 15f, FontStyle.Bold);
                        string hex = "#2791b9";
                       
                    }
                }

                //here I am cropping and showing that part in bottom of the icVideo
                using (Graphics g = ob.GetGraphics())
                {
                    int liveVideoX = -300;
                    int liveVideoY = (int)(icVideo.Height - 100); // Adjust the Y position as needed
                    int liveVideoWidth = (int)(icVideo.Width + 450);
                    int liveVideoHeight = (int)(icVideo.Height);  // Adjust the height as needed

                    Rectangle liveVideoRect = new Rectangle(liveVideoX, liveVideoY, liveVideoWidth, liveVideoHeight);

                    // Crop and draw the live video
                    g.DrawImage(icVideo.ImageActiveBuffer.Bitmap, liveVideoRect);

                    // Zoom the cropped live video
                    g.DrawImage(icVideo.ImageActiveBuffer.Bitmap, new RectangleF(liveVideoRect.X, liveVideoRect.Y, liveVideoRect.Width * 2, liveVideoRect.Height * 2));
                }


                //code for diamond
                if (isDrawDiamond)
                {
                    Drawdiamond();    //diamond drawing function
                }


            }
            catch (Exception ex)
            {
                ////MessageBox.Show("line: 865" + ex.Message);

                WriteErrorLog(ex);
                // MessageBox.Show("Drawing Error :" + ex.Message);
            }

        }
Posted
Comments
[no name] 4-Feb-24 14:09pm    
I think you're handicapping yourself mixing "WPF" and (mostly) "non-WPF" code. "Pure" WPF should be able to do this better and cleaner. e.g. Instead "DrawTexT", one positions a "Textblock" control, etc. A ViewBox or ScrollViewer or Border or negative Padding, etc. (i.e. "layout) can handle "cropping", etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900