Windows Develop Bookmark and Share   
 index > Windows Forms General > Crop Image Possible?
 

Crop Image Possible?

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

You can use google to search for other answers

Custom Search

More Threads

• Enhancing UI layout using TableLayoutPanel Programmatically?
• Displaying Lookup Values in a DataGridView instead of Foreign key's
• .ini file form input
• Problem with Microsoft Office Word contents
• Best practice to email all our members
• Assign Value and Text to CheckedListBox. Help Please
• Drawing outside of your Form
• I need a lot of help with a Treeview control
• Tracking movement of a foreign window
• Running file from app