1

I am trying to reduce employee picture before uploading. checked for help but the all the answers are very much confusing. And I am here to ask help from experts :)

I am opening image to my picture box through below code

OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|All Files(*.*)|*.*";
dlg.Title = "Select Employee Picture";
if (dlg.ShowDialog() == DialogResult.OK)
{
Image im = new Bitmap(dlg.FileName);
picEMP.Image = im;
string imgloc = dlg.FileName.ToString();                    
}    

and making the image to binary with below codes

byte[] img = null;
FileStream fs = new FileStream(imgloc, FileMode.Open, FileAccess.Read);
                        BinaryReader br = new BinaryReader(fs);
                        img = br.ReadBytes((int)fs.Length);  

and finally uploading with a parameter value

command.Parameters.Add(new SqlParameter("@img", img));        

But I am not checking image size. I want to check the image size or the resolution(height, width) and reducing image size with a fix size like (188,222) and then upload image to my sql server. My SQL connection code is below:

SqlConnection conn = new SqlConnection("Data Source=host; Initial Catalog=TimeAttendance; User ID=id; Password=password"); 

Please Help .......

Bappy
  • 109
  • 1
  • 3
  • 14
  • You'll need to use a graphics library such as the GDI+ libraries of .NET to manipulate the image and scale it, etc. [GDI+](http://msdn.microsoft.com/en-us/library/aa984108(v=vs.71).aspx) – Haney May 02 '14 at 18:45
  • Are you trying to make the width and height of the image smaller or do you just want to reduce the number of bytes being stored in SQL? – Rick S May 02 '14 at 18:46
  • @RickS I think the former: "I want to check the image size or the resolution(height, width) and reducing image size with a fix size like (188,222)" – Haney May 02 '14 at 18:51
  • possible duplicate of [Scaling a System.Drawing.Bitmap to a given size while maintaining aspect ratio](http://stackoverflow.com/questions/10442269/scaling-a-system-drawing-bitmap-to-a-given-size-while-maintaining-aspect-ratio) – DarkWanderer May 02 '14 at 18:59
  • All I want to do is decrease the image size so that it block not much then 50kb to my db. currently if I choose an image of 5MB it block the same space so that it takes much time to load. want to remove the size of the image. – Bappy May 04 '14 at 11:32

1 Answers1

0

Have you tried zipping it up and compressing it. The below library should work pretty well for that.

http://dotnetzip.codeplex.com/

Bailcm
  • 1
  • 1