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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Resize and Crop an image using the graphics.drawimage method

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

Hello all,

I have been pulling out my hair trying to get this figured out and I need to tap the wisdom of the dotNet elite.

I am running dotNet 3.5 (VB.NET) , IIS7, Windows 7.

Basically, I have constructed a UI using a combination of two JQuery tools. JCrop and Resizable. Both are working on the client side and I need to save the optionally resized and optionally cropped photo after the user has completed their image manipulation.

At the moment, I have a class file that resizes images on the fly and crops them. But they scripts to handle the resized image and the cropped image are separate.

Here is the specifics:

            Dim image As New Bitmap(ThumbWidth, ThumbHeight)
            Dim g As Graphics = Graphics.FromImage(image)

            ' Load the file data.
            Dim thumbnail As System.Drawing.Image
            If ImageProcessType = ProcessType.Filename Then

View Complete Post

More Related Resource Links

Graphics.DrawImage(image, bounds) vs SetResolution

Hi    this is what I am undertanding.   Image object never store inch information, it is two-dimentional array of pixels, thus Image object don't have a DPI.    so I conclude that Image.SetResolution is actually changing the Image width and height with the current Graphics.InterpolationMode   from the naming of enumerations of Graphics.InterpolationMode I conclude it is a Re-Sampling algorithms.   thus   If I am drawing image in terms of inches then   Image.SetResoultion(Image.Width * someFactor/ DPI, ........);  Graphics.Draw(Image)   is equivalent to   Graphics.Draw(Image, Bounds in inch)   Can some one validate this?

Problem with Graphics.DrawImage method in .Net on Windows 7 OS



We are displaying bitmap image on winform header in our dotnet application. It is displayed well on all windows operating systems. But, the same dotnet code if it runs on windows7, it does not display the image on the form. Can you please help me? Here is our code:


Dialogbase {


Rectangle captionRect = new Rectangle(0, 0, 0, 0);


Image processing, determine white space and crop



I have created a image upload for our ID card system to allow users to upload new images, edit them and submit for approval.  This is all working well with a combination of asp.net (c#) and jquery to give a seemless editor etc.

We have had a few users who I cannot believe have scanned a photo of themself and then just submitted it with the A4 page of white and little photo.

I am wondering if anyone can help with a suggestion on how I could possibly reduce the load of these coming through (I can't believe they can be this stupid), it stipulates UK passport standards.

Would my only option be to check for a single continues colour that occurs and if it reaches a certain percentage point say 60% then to just send back an error stating they need to crop the image.

Can anyone help with providing sample or that I can use to move this one on.

I am still in disbelief on this one.  the other one is they take a photo of whole body and other in it and cut straight down middle chopping the people out but supplying a photo that no use for an id photo card....but that I can't imagine being solved programatically as I need to determine where their face dimensions are and what percentage of the actual photo is taken up by it and if it below a threshold reject it.

Easy image processing(grayscale, sepia, negative, resize, brightness, contrast and opacity)

Howdie y'all,

I see a lot of questions in this forum about resizing images. Recently I created a code sample(with downloadable webapp), right here.

The class (downloaded or created) allows for very fast and easy processing of your images. And a lot of problems over here can be solved by simply using that class. I thought it might help to mention the code sample in this forum as well.



Resize image

Hello, am writing code for upload image file and save it into disc ,,, during this and before save it to disc I want to resize the image into specified width and Heigh  am trying to use this code if (this.IsValid && this.FileUpload1.HasFile) { //Create an ImageElement to wrap up the uploaded image Neodynamic.WebControls.ImageDraw.ImageElement uploadedImage; uploadedImage = Neodynamic.WebControls.ImageDraw.ImageElement.FromBinary(this.FileUpload1.FileBytes); //Create Resize imaging action to apply on the uploaded image //NOTE: You may apply any of the ImageDraw built-in imaging actions Neodynamic.WebControls.ImageDraw.Resize actResize = new Neodynamic.WebControls.ImageDraw.Resize(); actResize.Width = 150; actResize.LockAspectRatio = Neodynamic.WebControls.ImageDraw.LockAspectRatio.WidthBased; uploadedImage.Actions.Add(actResize); //Composite the output image by using ImageDraw class Neodynamic.WebControls.ImageDraw.ImageDraw imgDraw = new Neodynamic.WebControls.ImageDraw.ImageDraw(); //Add uploaded image imgDraw.Elements.Add(uploadedImage); //Now, save the output image on disk string fileName = @"../images/" + System.IO

image resize according to user options

i want to provide user to select images to upload, maximum images is 4.the overall size is 1024px width and 500px height.within this 4 or 3 or 2 images will have to fit.if the user upload 4 images it has to calculate the overall width and height and resize the 4 images as equal width and height for each.if the user upload 2 images it has to calculate the overall width & height and fits.i want to do through code. iam using c# asp.netif any samples plz provide me.

select image , show image, crop image and then submit to server.

How do i do this using javascript, asp.net 3.5 and C# ?step 1) user selects the image using browse buttonstep 2) clicks on upload button -- when user clicks on upload button i have to show the image immediately before sending the image to server, because, 1) image size could be very large 2) image dimensions could be long where my application shud not accept.step 3) ask the user to select the region (like face) from the image, zoom in /zoom out step 4) click on submit button to send the selected region to the server and then save it on the server as image.I have seen couple of tools but are not useful to me.Is there any tool that follow these steps?I want to do the work @ client side,with which 1) i can reduce the amount of data transfer.2) user have the option of selecting the image and play around with it.any help would be highly appreciated.thankssuman

resize image

Image img = Image.FromFile(this.tbPic1.Text.ToString()); Clipboard.SetImage(img); richtextbox1.SelectionStart = 0; rtbrichtextbox1Paste(); Clipboard.Clear(); i can insert picture to richtextbox,but how can i set the width and heigh of the picture before paste into richtextbox. one more question i would like to ask about image in MS Access Database how can i store the image into database using ODBC

Auto resize image width only


I have a question regarding the resizing of images.

My problem is that I would like to resize files that are being uploaded automatically. But I only want to resize the width.

Regarding the height of the file, this should auto adjust it self. Forexample; If I'm uploading a file that is 1000 px in width and 2000px in height and then resize it to 500px in width, then I want the height to be auto resized to 1000px. In other words the height and width has to be proportional. 

Could someone help me out on this. 

Thanks for reading. 

Resize image in gridview


I have a database which stores the path of an image. When the gridview displays, it uses a template field to show the image instead of the path. 

<asp:TemplateField HeaderText="Image">
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Image") %>' />


The images in this database may be different to eachother, but I want to resize each picture by a scale factor. Ie. Divide the height by 10, and then the width by 10, then set the height and width to these values. How can I do this for each image in the datagrid?

dynamic Image resize


Hi guys,


I'm trying to dynamically load an image from my code behind file,  however I want to be able to resize the image thus reducing the file size sent to the client.  I've come across a few samples but without much luck.  So far I have the following:

        Dim MyImage As Image
        MyImage = Image.FromFile("d:\flowers.jpg")
        MyImage = MyImage.GetThumbnailImage(100, 100, Nothing, New IntPtr)


Unfortunately I now need to load this image into control panel.but nowhere can I find how to do this.

asp.net vb

how can i call the AsyncFileUpload's click method by a image



i want to make something like that

<cc1:AsyncFileUpload runat="server" id="upload"

<img onclick='upload.click()'/>

i tried lots of script but it doesnt work. Can anyone help?

DetailsView Image Resize on Upload


I am using a details view to add a name and image path to a database. I have a template with a fileupload control and a dropdown list (landscape and portrait), that is used to get the file name. My question is: How can I resize the image based upon whether the image is landscape or portrait? This is my code so far:

<%@ Page Title="" Language="VB" MasterPageFile="~/Admin.master" AutoEventWireup="false" CodeFile="UploadGallery.aspx.vb" Inherits="Admin_UploadGallery" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h1>NTTC Administration: Upload Pictures to Gallery</h1>
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="318px" 
        AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
        DefaultMode="Insert" GridLines="None">
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                ReadOnly="True" Sor

Resize image and get new byte size without saving it


Hi Guys,

I'm making an application that needs to be able to take a user specified image file and upload it into a database that only accepts images of 10 KB or less. So I want to let the user select an image and then have the option of resizing it and if possible also decreasing the quality - I'm sure I can figure out how to do both of these things on my own but the thing I'm not sure about is how I can tell what size the resulting image will be without actually writing it to disk. I thought the SourceStream property of the BitmapSource class would be useful but when I try to access it I just get told that the stream has been closed. Any ideas?




My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com

image zoom and crop using javascript



i am using jquery jcrop script to crop the images, what it lacks is zoom-in and zoom-out effect.

you guys have any idea of such scripts?

1) user uploads the image to the server.

2) user will be shown image what he/she uploaded to the server.

3) i need zoom in & zoom out effect. he should be able to zoom as he like.some thing like kropper script. where u get this zoom effect.

4) crop the image

5) save the modified image to server.

I am looking for such scripts, any opensource, freeware tools?


how to resize Image on imagemap


Hi All,

             This is praveen,i have faced one problem please help me any one, it is very urgent, The Position of the Number seems to be absolute on the page,it menas i have taken one image, on that image i have placed one more image with absolute position,in the browser leve 100% ok all images dispaly very good,but when we resize the browser not go with image on image, is there solution to solve this one....................this small images dispaly dynamically generated for Hotspots on image map............................

Thanks In advance:


mali id:nanna.praveenm.hyd@gmail.com

Parameter is not valid exception on image.fromstream() method



      i have written a code for resizing the images and its working good except for some images that too the issue is occuring only on locolhost(IIS). I have asynchronous file upload contorl and two button  controls. when clicked on first button  the asynchronous file upload control is saved in session using the following code

Session["myupload"] = AsyncFileUpload1.PostedFile;

The image is resized and saved in a folder when second button clicked. The following code will execute when clicked the second button.

HttpPostedFile hif = (HttpPostedFile)Session["myupload"]                        
                        if (hif.ContentLength <= 20000000)
                            if (checkfiletype(hif.FileName))
                                string spacefileName = hif.FileName;                                
                                string storePath = Server.MapPath("~") + "/Docs";
                                //MemoryStream source = hif.InputStream;
                                Stream source = hif.InputStream;
                                //source =(MemoryStream)hif.InputStream;
                                byte[] input=new byte[hif.ContentLength
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