Guest User

Guest User

  • Tech Writer
  • 271
  • 36.2k

compress image & save to database in asp.net

Aug 18 2020 1:08 PM
hello..
 
i want to compress an image and save to database...i also try imageprocessor nuget package but its beyond my limits....
  1. protected void btnSave_Click(object sender, EventArgs e)  
  2. {  
  3. Model.WallpaperCategory newusermodel = new Model.WallpaperCategory();  
  4. string str = fileUpload1.FileName;  
  5. fileUpload1.PostedFile.SaveAs(Server.MapPath("~/Upload/" + str));  
  6. string Path = "~/Upload/" + str.ToString();  
  7. foreach (string strfileName in Directory.GetFiles(Server.MapPath("~/Upload/")))  
  8. {  
  9. ImageButton imagebutton = new ImageButton();  
  10. FileInfo fileinfo = new FileInfo(strfileName);  
  11. imagebutton.ImageUrl = "~/Upload/" + fileinfo.Name;  
  12. imagebutton.Width = Unit.Pixel(100);  
  13. imagebutton.Height = Unit.Pixel(100);  
  14. imagebutton.Style.Add("padding""5px");  
  15. form1.Controls.Add(imagebutton);  
  16. imagebutton.Click -= new ImageClickEventHandler(imagebutton_Click);  
  17. newusermodel.Path = Path;  
  18. newusermodel.Category = ddlWallCategry.SelectedItem.Value;  
  19. newusermodel.Thumbnail = Path;  
  20. newusermodel.CategoryName = ddlWallCategry.SelectedItem.Text;  
  21. }
in my code firstly i select image from fileupload then after i show thumbnail images on save button click...My senerio is when its save to database(thumbnail column) its size compress 

Answers (3)