Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to load Image in C# and set properties of the Picture Box

Author: DevASP
Download Source Code : 385_load_image.zip

In this article one can learn that how to load the image to display it on form in C# also how to set the properties of the picture box i.e. Stretch Image, Auto Size image and Center image.

In this article one can learn that how to load the image to display it on form in C# also how to set the properties of the picture box i.e. Stretch Image, Auto Size image and Center image at run time.

 

Create a C# application drag a picture Box, four buttons and open file dialog on the form.

 

Write code on btn_browse Button click

 

private void btn_browse_Click(object sender, System.EventArgs e)

{

try

      {

OpenFileDialog open = new OpenFileDialog();

open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

            if (open.ShowDialog()==DialogResult.OK)

            {

                  pictureBox1.Image = new Bitmap(open.FileName);

            }

      }

      catch (Exception)

      {

            throw new ApplicationException("Failed loading image");

      }

}

 

Write code on btn_StretchImage Button click

 

private void btn_StretchImage_Click(object sender, System.EventArgs e)

{

pictureBox1.SizeMode =  System.Windows.Forms.PictureBoxSizeMode.StretchImage;  

}

 

Write code on btn_AutoSize Button click

 

private void btn_AutoSize_Click(object sender, System.EventArgs e)

{

pictureBox1.SizeMode =  System.Windows.Forms.PictureBoxSizeMode.AutoSize;

}

 

Write code on btn_CenterImage Button click 

 

private void btn_CenterImage_Click(object sender, System.EventArgs e)

{

pictureBox1.SizeMode =  System.Windows.Forms.PictureBoxSizeMode.CenterImage;

}
Article Comments
how to place picture image at runtime in C#

Posted on 8/2/2006 6:00:44 AM by geetha

thanks this has helped me.
Christ reign in u

frm Uganda

Posted on 2/9/2007 5:47:21 AM by Kwagala

thanks this has helped me.
Christ reign in u

frm Uganda

Posted on 2/9/2007 5:47:23 AM by Kwagala

How to Increase the image Size?
i mean increamenting height ,Width of the image.

Posted on 3/28/2007 12:01:07 PM by Kamran

How to Increase the image Size?
i mean increamenting height ,Width of the image.

Posted on 3/28/2007 12:04:07 PM by Kamran

woudl you please tell me way to Load and Zoom image in C#
Thank you very much

Posted on 4/9/2007 5:32:54 AM by vu cong tam

You guys are very greate. thank you very much the work you doing here. this site has helped me with pictures

Posted on 4/10/2007 1:54:37 PM by Mukuwa James

Thank you. I can load any image i want know at runtime :)

Cheers !

Posted on 12/26/2007 1:57:02 PM by Abhishek

Thank you. I can load any image i want know at runtime :)

Cheers !

Posted on 12/26/2007 1:57:17 PM by Abhishek

Thank you. I can load any image i want know at runtime :)

Cheers !

Posted on 12/26/2007 1:57:34 PM by Abhishek

Thank you. I can load any image i want know at runtime :)

Cheers !

Posted on 12/26/2007 1:57:45 PM by Abhishek

Hi,

Above code article is good.but i have one problem, that is i want to place gif file basex on X,Y coordinates.is it possible to do that.
can you help me id it is possible.

thanks
regards
Venkat

Posted on 12/26/2007 11:12:25 PM by Venkat

Hi
Apart from being able to get the image from file using the open file dialog is it possible for you to be able to reference the image in am sql mobile database?
Any help will be appreciated

Posted on 1/14/2008 3:40:41 AM by Ken

Perfect, thank you very much

Posted on 1/14/2008 10:21:41 AM by Selim

hi,
i work a project .
i want to some help.
i want to load/upload image form sqldatabase using DetialViewer in asp.net.
i am waiting for u feedback

Posted on 3/17/2008 5:44:52 AM by sachin

This is fine...can u help me smthing abt SIFT?

Posted on 4/20/2008 6:51:22 AM by Shubham Agarwal

Thank u very much

Posted on 10/31/2008 5:37:12 AM by chandralatha

Hey man, I love you man, you are the best. I've waste 3 hours
searching for an example like yours.

You are the best man.

Posted on 11/2/2008 6:51:07 PM by Diego

nice.
but try to upload that image into a database.
that will improve you.

Posted on 12/3/2009 10:23:10 AM by tamer

Hi..thanks for providing code...

Posted on 12/13/2009 11:28:33 AM by Parul

wow..its really working....thank u very much....its really very useful.....

Posted on 12/21/2009 1:23:18 AM by umesh

Thanks it has helped me!!

Posted on 12/22/2009 3:00:13 AM by Mehwish Kayani

yes its really helpful but its not enough you have to provide more functionality to enhance your application.

Posted on 12/28/2009 9:47:05 AM by mukesh vishwas

Thanks for this short tutorial - I like short and precise.

Posted on 1/8/2010 6:27:24 AM by Ecki

Thanx...It helped me.

Posted on 2/2/2010 3:41:30 AM by Payal

crisp one...i like it...thanks

Posted on 2/11/2010 2:23:52 PM by vipsa

how to write code for refresh button ,pause button,take a screen shot button,show the picture by using push button

Posted on 2/14/2010 2:18:35 PM by abeysinghe

thanks! it works but still we have sum problem about uploading it in the database ...

Posted on 2/15/2010 10:41:46 PM by chee

how can i saved a image in sql2005 database through picturebox????

Posted on 2/19/2010 2:05:09 AM by abhishek

how to zoom an image in c #?

Posted on 2/24/2010 6:02:32 AM by nb

Thanks a lot....

Posted on 2/26/2010 10:21:26 AM by N.Senthuran

Dear friends.

I need how get Picture box image file location(path) to Textbox or Label.

regard
Senthu.

Posted on 2/27/2010 6:45:07 AM by N.Senthruan

its so simple

Posted on 3/15/2010 5:40:28 AM by DYANI

thank you very much, this code piece really help me out!!! i o u 1

Posted on 3/21/2010 2:07:06 PM by yorsh

hi;
i am doin pjt in asp.net 2008 with c# script.i dont knw hoe to zoom aimage from one form to another.

Posted on 3/23/2010 1:40:40 AM by nancy

i am able to insert a picture in picture box.but i couldn't get total image in picture. it is displaying only some portion of the picture which fits in picture box.as my picture size is big.i should get complete image in the picture box.if i select the aUTOSIZE property the picture box size is increasing.I should get the whole picture in the picture box with out increasing the picture ox size i.e., without using autosize. plzzz help me.

Posted on 4/4/2010 2:29:57 AM by pavan

plzz rply

Posted on 4/4/2010 2:30:29 AM by pavan

In my application i have a picture box and picture box control,i need to set image from picturebox to my picturebox control which is present in form2 and not on mainform but my picturebox is on main form.so what to do ?? so please let me know the piece of code for it.

Posted on 4/9/2010 5:59:17 AM by Aasif

First i would like to thank u for provinding such type of kind ness than i need to know how i can load a pic directly from an ip camera if u provide this type of kindness i will much thankful for u

Posted on 4/20/2010 2:57:00 PM by Umair

Do you have to use a .bmp file for new Bitmap(" "); ?
and if so, is there any particular bitmap detail you have to have? like 8bit, 16bit.

Posted on 4/24/2010 10:42:30 AM by Maelstrom

Thanks for helping me out with opening and processing the image files

with regards,

milind

Posted on 6/14/2010 9:33:44 AM by milind

thanks you very much

Posted on 6/23/2010 4:27:19 PM by kudo_219

Thanks A Lot.

Posted on 7/2/2010 7:54:21 AM by InvisiblePrince

hi
how to retrive images from datagrideview to see it in picturebox c#

Posted on 7/4/2010 2:00:22 PM by bahar

Thank u...;-)

Posted on 7/11/2010 2:36:04 AM by sweet !diotz

nice! thanks a lot!

Posted on 7/22/2010 5:41:31 AM by instanceOf

thank you for this code that is very good

Posted on 8/28/2010 2:12:18 AM by zryan

hi
thanks to all who prepared programs.
its too helpful for all users...........................

Posted on 9/28/2010 2:03:11 AM by sandeep

thanks for the code God Bless Amen!

Posted on 11/8/2010 7:26:09 AM by anthony

Thank a lot

Posted on 11/10/2010 12:34:45 PM by asela

thankyou so much.

:)

Posted on 11/15/2010 12:13:15 PM by Muhammad

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Calling Win32 API Calls from C# using Platform Invoke

Disclaimer - Privacy
© 2002-2014 DevASP.net