.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

Auto resize image width only

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net

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. 

View Complete Post

More Related Resource Links

how to auto resize image then upload ?


how to auto resize image then upload??

any1 can help me?


below is my code:

 If FileUpload1.HasFile Then
                filename1 = FileUpload1.FileName
                savePath1 += filename1

                sSQL1 = "SELECT * from news order by PicID desc"
                conn1 = New SqlConnection(ConnStr)
                cmd1 = New SqlCommand(sSQL1, conn1)
                rd1 = cmd1.ExecuteReader()
                Dim n As Integer
                n = rd1.Item("PicID") + 1
                sSQL = "select * from news"
                conn = New SqlConnection(ConnStr)
                cmd = New SqlCommand(sSQL, conn)
                da = New SqlDataAdapter(cmd)
                cb = New SqlCommandBuilder(da)
                ds = New DataSet
                da.Fill(ds, "news")

                nrow = ds.Tables("news").NewRow()
                nrow("PicID") = n
                nrow("ImagePath") = "~/new/news_images/" + filename1
                nrow("Tittle") = tittle
                da.Update(ds, "news")

                FileUpload1.SaveAs(Server.MapPath("/new/news_images/" & filename1))
                lblmsg1.Text = "Image Upload Successful!"

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

How to auto set forms width automatically on different versions of windows OS.

How to auto set forms width automatically on different versions of windows OS.My application running on Windows Server 2000 Pops a new windows forms side by side the MDI and fits without overlapping.  When the same application is hosted on Windows Server 2008 and the new window pops up, it is overlapping on the existing MDI.

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.

Auto-generating Name When Saving an Image

hi guys, I have a toolbar on my chart:  <Toolbar Enabled="True"> <Items> <dcwc:CommandUIItem CommandName="PrintPreview" /> <dcwc:CommandUIItem CommandName="Print" /> <dcwc:CommandUIItem CommandName="Separator"/> <dcwc:CommandUIItem CommandName="SaveImage" /> <dcwc:CommandUIItem CommandName="Separator" /> <dcwc:CommandUIItem CommandName="UserDefined_1" /> </Items> </Toolbar>     For the SaveImage, I want to be able to set my image name with its own name. the name can be found using:   string fileName = Request.PhysicalApplicationPath + @"graphs\"+User.Identity.Name+graphID+".jpg"; Right now, when I click save, it always show chart.png And also, I want to download the chart as jpg.   thanks guys.

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

TabContainer Auto Height and Width


Hi all,

How i can set auto Width and Height? it can be resize according to the data populate inside TabPanel.

Thank You

Change dimensions of image if width exceeds certain amount


(In a different post  I asked about how to access an Image control held in a FormView template. This topic has been mixed into it, so I thought I would start a fresh post only about this problem.)

I would like to perform a simple check to ascertain the width of an image. If it exceeds a certain dimension I would like to give the image a width property. I understand this doesn't not affect file size, just dimensions, but it is for presentation purposes. I'm still learning VB, but the code below is what I have tried so far:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim LargeImage As Image = DirectCast(FormView1.FindControl("Image1"), Image)

        Dim Width As Integer
        Width = LargeImage.Width.Value

        If Width > 560 Then
            LargeImage.Width = Unit.Pixel(560)
        End If

    End Sub


Thanks in advance,


Detect Width and Height of .jpg image



I have an image on this path that I first check if it exists. If it exists I wonder what the method is to get width and height of this image ?

            if (File.Exists(Server.MapPath("Images\\Pic1.JPG")))
		    //How to get the Width and Height of this JPG Image ?


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

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

Where to find width of ImageButton after the image has been loaded?


I have an ImageButton that loads different images (of differening sizes) based on a selection made by the user from a dynamic data list. This ImageButton is displayed beside the DetailView. I want to get the width of the DetailView (which is static) and the width of the ImageButton so I can set the width of the Div they are contained in to the sum of their width, plus a few px. Once I set the width of the DIV and I set and margins (left and right) are auto, the DetailView and ImageButton will be centered in the page. However, every way I've tried to get the ImageButton width, it is always zero. I've trying coding the ImageButton Load event and its PreRender event but I get zero in both cases. Do I need to check some other property, or another event, like maybe one from the form itself?


Auto-resize ColumnDefinition


I have a text string in a TextBox which is in row 0, column 0 of a Grid which is in a DockPanel which is on a Page which is in a NavigationWindow. I am trying to size the width of Column 0 based on the ActualWidth of the string. I am missing something, possibly that the TextBox is not getting resized to fit the length of the string. (I couldn't find an autoresize property for TextBox.) My approach so far is to resize the ColumnDefinition when the TextBox is Loaded.


Inside my Grid subclass, I have this:

myTextBox.Loaded += (s, e) => this.ColumnDefinitions[0].Width = new GridLength(myTextBox.ActualWidth, GridUnitType.Pixel);


However, the column width remains the same as when it is created. A breakpoint shows the above line being executed with the ActualWidth being the (too large) value it has when constructed, not what I hope it is when loaded (smaller from a correct measurement). Any ideas?

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

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

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