using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
using System.Web.UI;
using System.Drawing.Imaging;
namespace Ecommerce.BLL
{
public class ImagesManager
{
///
/// This method is used to upload images according to height width
///
///
///
///
///
public void Bll_UploadImages(string FileName,int width, int height, string SaveName)
{
Bitmap oCounter;
Graphics oGraphics;
oCounter = new Bitmap(width ,height);
oGraphics = Graphics.FromImage(oCounter);
FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate);
fs.ReadByte();
Bitmap objImage = new Bitmap(fs);
oGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
oGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
oGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
oGraphics.DrawImage(objImage, 0, 0, width, height);
oCounter.Save(SaveName);
objImage.Dispose();
oCounter.Dispose();
fs.Dispose();
File.Delete(FileName);
}
}
}
================================================================
protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
{
if (ViewState["ImageID"].ToString() == "")
{
objBol.Products_imageID = -1;
}
else
{
objBol.Products_imageID = Convert.ToInt32(ViewState["ImageID"]);
}
objBol.ProductsID = Convert.ToInt32(ViewState["ProductsID"]);
objBol.ColourID = Convert.ToInt32(DropColour.SelectedValue);
objBol.Colour_name = DropColour.SelectedItem.Text;
objBol.Icon_image = "";
objBol.Medium_image = "";
objBol.Large_image = "";
objBol.default_style = false;
int retval= objBll.BLL_InsUpdProductsImages (objBol);
if (retval > 0)
{
string strImagePath, strSavepath;
strImagePath = retval.ToString() + "1.jpg";
strSavepath = retval.ToString() + ".jpg";
if (ProductImageUpload .FileName != "")
{
// small icon
string strsmalliconPath = Server.MapPath("~/ProductsImages/Small/" + strImagePath);
string strsmalliconsavePath = Server.MapPath("~/ProductsImages/Small/" + strSavepath);
ProductImageUpload.SaveAs(strsmalliconPath);
objImg.Bll_UploadImages(strsmalliconPath, 50, 50, strsmalliconsavePath);
//icon image
string striconPath = Server.MapPath("~/ProductsImages/Icon/" + strImagePath);
string striconsavePath = Server.MapPath("~/ProductsImages/Icon/" + strSavepath);
ProductImageUpload.SaveAs(striconPath);
objImg.Bll_UploadImages(striconPath, 120, 120, striconsavePath);
//medium image
string strMediumPath = Server.MapPath("~/ProductsImages/Medium/" + strImagePath);
string strMediumsavePath = Server.MapPath("~/ProductsImages/Medium/" + strSavepath);
ProductImageUpload.SaveAs(strMediumPath);
objImg.Bll_UploadImages(strMediumPath,288, 360, strMediumsavePath);
//large image
string strLargePath = Server.MapPath("~/ProductsImages/Large/" + strImagePath);
string strLargesavePath = Server.MapPath("~/ProductsImages/Large/" + strSavepath);
ProductImageUpload.SaveAs(strLargePath);
objImg.Bll_UploadImages(strLargePath, 576, 720, strLargesavePath);
}
}
DisplayProductsImages();
ViewState["ImageID"] = "";
}
No comments:
Post a Comment