.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Thumbnail resizing and cropping

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :Windows Application

Hi ,

I am using Graphics object to resize and crop an image and then finally save it to the disk.

I am either able to resize or crop but not both.

May be I am not passing the parameters to the graphics object correctly.

Just to add that my original image is of size 50 * 50.

I would first need to increase the size to  100 * 100 and then crop it to fit in 75 * 75 size.

(the requirement is not to scale it to 75 * 75 directly.

but to first resize to 100 * 100 and then crop it to 75 * 75 and then saving it.)

I think I am not using the Graphic object and Image object in the right way , passing it dimensions in wrong locations and hence it is either cropping or resizing but not doing both. Please help.

View Complete Post

More Related Resource Links

C# Tutorial - Image Editing: Saving, Cropping, and Resizing

In C# it can be tiresome to do certain image editing functions using GDI+. This post has some fun editing methods which can come in handy at times. I have also included a nice little C# program to show all the functionality of the methods below.

Saving a Jpeg
The first thing to do here is set up the method signature with the input parameters. These are the save file path (string), the Image to save (System.Drawing.Bitmap), and a quality setting (long).

How to position one control relative to another one even after resizing windows?


I used following Jquery code trying to make image close to a table. It worked fine after first load, but the position changed after window is resized. Any ideas? thanks

$(document).ready(function() {
            var pos = $("#mytable").offset();
            var width = $("#mytable").width();
            var left = pos.left + width + 20;
            var top = pos.top + 200;
                position: 'absolute',
                zIndex: 5000,
                left: left,
                top: top

OutOfMemory when resizing image


I've been pulling my hair out on this one. I have a image gallery module in asp.net. I'm using Telerik RadUpload to upload a sinlge image. I then save the image on the server and create a thumbnail and save it as well. There is no loop involved and is one at a time. It always seems to work when I run it locally on Windows 7 (IIS7) but on the server IIS6 I keep getting OutOfMemory errors. The images I'm trying are barely 1MB so not huge files. I've gone through google and bing over past several days and can't seem to find a solution. In my resize methods I'm using the "using" statement on the image reference, etc. I can pretty much always make it fail with the 3rd line below:

ruPhoto.UploadedFiles[0].SaveAs(Server.MapPath("~/DesktopModules/Gallery2/Photos/" + newPhotoName));
System.Drawing.Image photo = System.Drawing.Bitmap.FromFile(Server.MapPath("~/DesktopModules/Gallery2/Photos/" + newPhotoName));
//System.Drawing.Image img = new System.Drawing.Bitmap(photo); <--- will cause outofmemory error

if I just use the photo variable then the OutOfMemory will occur later in the resize code.

Any help would be greatly appreciated.

Problem displaying a page using window.showModalDialog when resizing it.

 Hi, I have a page that is displayed using window.showModalDialog, when the page is resized the tables, text boxes and everything else that is in the page with the width 100% doesn't resize (fit the page) unless a post back is used.How can I make the page keep everything in proportion when it is resized without the need to post back? 

Expandable ContentControl resizing issue

Hi , I am having a list of expanders.. inside those expanders there are  some forms On expand and collapse i am showing animation like we have in accordian... For the animation i have made use of ExpandableCOntentControl... Every thing works fine.. Only there is one issue.. Some of the forms have add function whihc will add some controls in the UI.. But when the controls are addded my expander doesnot stretch  and as a  result my controls get cut.... But when i  collapse and expand again my expander then i am able to see all the ocntrols properly.. Please help me in this...          

Conditional resizing using GridSplitter

I am having a Grid with 5 rows (only one column). Each row has a Canvas on it and I am using the GridSplitter control to resize the rows. I am having a minimum height and maximum height for all these canvases and do not want the user to resize beyond that range. How can I do this?

How to display the thumbnail view of the documents in Sharepoint Document Library

Is there a way that we can have the thumbnail view of the documents that are uploaded in SharePoint Document Library. We have thumbnail feature in Picture Library but can we have the same in Document Library too. Documents includes Words,Excel,PDF. Any Suggestions Please 

Get control over the other open windows to avoid resizing them

Hi, I am developing C# WinForms application. I need to have control over the other open windows to avoid resizing them. If a user try to resize the open document say myDocument.doc, i.e., word file, then i should avoid resizing that window and set back to its previous size. I can get the Windows handle and Process ID and the File path of that document as well. Will any of these help me to solve my problem? Thanks for the help in advance. ViVidyadhar - V the destiny

Thumbnail view for the sharepoint picture library

Hi All, I have created the Thumbnail view for the sharepoint picture library. 1. I want the custom view to be availiable for every picrture library automatically. When ever user create a picture library then that view will come automatically   2. Is there a way for Documents in Document library to get little preview in thumbnail images ( any Docs like pdf,.ppt,doc) Any help is much appreciated.  Hanif

Regarding GridView Column Resizing in .net

Using System.Web In asp:Gridview ,Users can double-click the gripper to the right of a column header in order to resize a column to fit its content.

Create thumbnail on video upload

Hello,I am creating an upload control that will be used to upload videos.I am trying to get a thumbnail from any frame of the video being uploaded and save as thumbnail.does anyone have any idea where i can find some info on this.Thanks

Resizing and hiding a TableLayoutPanel

I have 3 TableLayoutPanels 1-OuterPanel and 2-InnerPanels: iPanel_1(inner bigger panel) and iPanel_2 (smaller).   What I want is: When user presses some button, the iPanel_2 should hide and iPanel_1 (with all the control it contains with Dock=fill option) should overshadow the display part which was owned previously by iPanel_2.   private void btnMainView_Click(object sender, EventArgs e) { Size oldSz_iPanel_1 = new Size(iPanel_1.Width, iPanel_1.Height); Size newSz_iPanel_1 = new Size(iPanel_1.Width, iPanel_1.Height + iPanel_2.Height);   //This will hide the innerPanel-2 HidePanelRowColumn(iPanel_2, 0, 0, false);   //This code should actually resize the iPanel_1 to overshadow iPanel_2. iPanel_1.Size = newSz_iPanel_1; }   protected void HidePanelRowColumn(TableLayoutPanel panel, int colIndex, int rowIndex, bool visibility) { panel.GetControlFromPosition(colIndex, rowIndex).Visible = visibility; }   Even when I assign: iPanel_1.Size = newSz_iPanel_1,  the Size of iPanel_1 remains as it was.   <Note> iPanel_1.AutoSize = true; iPanel_2.AutoSize = true;   Am I missing something?

Resizing tab panel

In a tab container after clicking on the Search button a grid will be visible. Now if I change the tab the grid will not be visible. So for that  I made document.getElementById( '<%= dtgSearchresults.ClientID %>').style .visibility ='hidden'; Now what happen I cant resize the panel, the grid is not visible but the size of the page is not refreshed.  Means suppose on the pageload gridview is not visible so at that time size= 100px, when the grid is visible it become 130px and when i move to another tab and come back again on that tab the size is remain 130px though the grid is not visible. Please provide some example and need javascript function only because I made tabpanel property autopostback= false. 

Create a Shell Extension Handler thumbnail extractor with .net?

Hi,My application creates nice graphics see http://www.mavericksplan.com/mavericks and it saves a custom document type.I'd like to show the contet of the document in Explorer when the user switch to Thumbnail view.To implement this feature I understand I need to create a Shell Extension Handler Thumbnail Extractor that extract the image from my file type to feed Explorer thumbnail vew, which is not easy at all for me.I look on the web and I found 1 C++ example and none in C#.Does anybody have a sample code to create a Shell Extension Handler thumbnail extractor with .net in C#?Thank youAndrea

Sharepoint 2007 Minimal Master Page Picture Library Thumbnail and FilmStrip issue



If i use custom master pages. For some reason a user cannot view the thumbnail or filmstrip view;  only the details view will display. No errors are thrown when a user selects the filmstrip or thumbnail view, in fact nothing happens at all.

If the master page for the site is changed to default.master then the picture library functionality returns.

Anyone can help me in this. Thanks in advance.

resizing image after jcrop


Hi guys,

I'm using JCrop, by using Mikes great article at: http://www.mikesdotnetting.com/Article/95/Upload-and-Crop-Images-with-jQuery-JCrop-and-ASP.NET

There are two things I haven't been able to figure out how to do though:

(1) How do I check if the uploaded image is big enough? (i.e. how do I determine width of image is > 200px")

(2) How do I resize the cropped image to 200px in width.

Any help/ideas would be very much appreciated.



Very slow repainting when moving or resizing an usercontrol in VS2008


After migrating a WinForm application with usercontrols that loads dynamically from VS2003 to VS2008 the usercontrols became extremly slowly when moving or resizing.

Gratefull for help and tips

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend