|
I have a panel with a background image that I need to "crop" just the right quarter of the image.
And then set that quarter as the backgroundimage (back in the same position:the right quarter...with the first 3/4 of the image "cropped out".
Is this possible?
I found examples to crop....but after cutting the quarter out...when I set the image...the quater can only be set starting at 0 left - (the first quarter position)
| | band object Tuesday, December 16, 2008 3:37 PM | Hi band object, Based on my standing, you'd like to have a part of a image displayed in part of your panel as backgroundimage. You can achieve it by handling paint event of the panel. Here's a sample drawing the specified portion of the specified Image at the specified location and with the specified size.
| privatevoidpanel1_Paint(objectsender,PaintEventArgse) |
| { |
| Imageimg=Image.FromFile("C:\\1.JPG"); |
| intwidth=img.Width; |
| intheight=img.Height; |
| inttoWidth=panel1.Width/2; |
| inttoHeight=panel1.Height/2; |
| RectangledestRect=newSystem.Drawing.Rectangle(panel1.Width/2,0,toWidth,toHeight); |
| RectangleorigRect=newSystem.Drawing.Rectangle(width/2,0,width/2,height/2); |
| Graphicsg=e.Graphics; |
| g.DrawImage(img,destRect,origRect,System.Drawing.GraphicsUnit.Pixel); |
| } | Wish thiscould help. If there's any problem, please feel free to let me know. Best regards, Steven Yu - Marked As Answer bySteven.Yu Monday, December 22, 2008 1:39 AM
-
| | Steven.Yu Thursday, December 18, 2008 2:30 AM | Cast the image to bitmap and clone it using an overload that takes a rectangle. | | JohnWein Tuesday, December 16, 2008 6:57 PM | Hi band object, Based on my standing, you'd like to have a part of a image displayed in part of your panel as backgroundimage. You can achieve it by handling paint event of the panel. Here's a sample drawing the specified portion of the specified Image at the specified location and with the specified size.
| privatevoidpanel1_Paint(objectsender,PaintEventArgse) |
| { |
| Imageimg=Image.FromFile("C:\\1.JPG"); |
| intwidth=img.Width; |
| intheight=img.Height; |
| inttoWidth=panel1.Width/2; |
| inttoHeight=panel1.Height/2; |
| RectangledestRect=newSystem.Drawing.Rectangle(panel1.Width/2,0,toWidth,toHeight); |
| RectangleorigRect=newSystem.Drawing.Rectangle(width/2,0,width/2,height/2); |
| Graphicsg=e.Graphics; |
| g.DrawImage(img,destRect,origRect,System.Drawing.GraphicsUnit.Pixel); |
| } | Wish thiscould help. If there's any problem, please feel free to let me know. Best regards, Steven Yu - Marked As Answer bySteven.Yu Monday, December 22, 2008 1:39 AM
-
| | Steven.Yu Thursday, December 18, 2008 2:30 AM |
|