Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
How do we manage the size of bigger images while saving in folder and path in database. When i save images to folder and show them in datalist and show slideshow using lightbox, my images comes to be very big.

This is my code for saving images:
C#
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
//Save images into SlideImages folder
fileuploadimages.SaveAs(Server.MapPath("Images/" + filename));
//Open the database connection

string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
MySqlConnection con = new MySqlConnection(conn);
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "Insert_Image";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("?description", "abc");
cmd.Parameters.AddWithValue("?fullstr", filename);

con.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
BindDataList();

Regards,
Inderjeet Kaur
Posted
Updated 29-Aug-12 23:44pm
v4

1 solution

You can't - unless you either look at the image and refuse to download (or save) big images, or you reduce the size of the image yourself before you save it. Which is best for you?
 
Share this answer
 
Comments
Inderjeet Kaur 30-Aug-12 6:50am    
How to set size of image while saving the path to database?
OriginalGriff 30-Aug-12 7:04am    
You don't - the path is just the path, it does not have any bearing on the item it is pointing at. If you mean to resize an image proportionately so it fits in a maximum-size-box then just load the data into an Image class instance, and use Graphics.DrawImage to draw it into a smaller bitmap before saving it to disk: http://msdn.microsoft.com/en-us/library/dbsak4dc.aspx
Inderjeet Kaur 30-Aug-12 7:17am    
I should resize picture while saving to folder or while retrieving it?
OriginalGriff 30-Aug-12 7:26am    
That is a good question! Personally, I hate throwing away information, but I also hate wasting processing time.
If you do it before you save it, then you only do it once, so you save space and processing time.
But, if you need it at a different size later, then you are throwing away information when you resize the image, so you will get a worse quality image that you could if you always keep the original. Takes more space though!

Only you can decide - you know what the purpose of the images is, I don't. :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900