Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

Save Bitmap Image Into JPG Format

public void saveJpeg(string path, Bitmap img, long quality)

{
try
{
// Encoder parameter for image quality
EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, quality);

// Jpeg image codec
ImageCodecInfo jpegCodec = this.getEncoderInfo("image/jpeg");

if (jpegCodec == null)
return;

EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualityParam;

img.Save(path, jpegCodec, encoderParams);
encoderParams.Dispose();
qualityParam.Dispose();
}
catch (Exception)
{
}


}


private ImageCodecInfo getEncoderInfo(string mimeType)
{
// Get image codecs for all image formats
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

// Find the correct image codec
for (int i = 0; i <>
if (codecs[i].MimeType == mimeType)
return codecs[i];
return null;
}


tag:Save Bitmap Image Into Jpeg Format

Upload and Resize Image in the Asp.net Using C#.Net .

const int IMAGE_WIDTH = 550;
const int IMAGE_HEIGHT = 176;
(We can change the Width and Height)



public void UploadImageAd()
{
try
{
string strFolderName = "Banner_Images";
string strFolderPath = Server.MapPath(strFolderName);
//string strSavePath = "~/" + strFolderName + "/";
string strFileName = string.Empty;
string strSaveFilePath=strFolderPath;
if (!Directory.Exists(strFolderPath))
{
Directory.CreateDirectory(strFolderPath);
}
if (FileUploadImage.HasFile)
{
strFileName = FileUploadImage.FileName;
strSaveFilePath += "/" + strFileName;
string strRealImagePath = Server.MapPath("RealImage");
strRealImagePath += "/" + strFileName;
FileUploadImage.SaveAs(strRealImagePath);
//Resize and Save Image
string strImageUrl = strRealImagePath;
ResizeImage(strImageUrl,strSaveFilePath);
//RealImage
//
m_strImagePath = "~/" + strFolderName + "/" + strFileName;
}

}
catch (Exception objException)
{
throw new Exception(objException.Message.ToString());
}
}


public void ResizeImage(string strImageUrl,string strSaveFilePath)
{
try
{
System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(strImageUrl);
System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(IMAGE_WIDTH, IMAGE_HEIGHT, dummyCallBack, IntPtr.Zero);
//Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property
thumbNailImg.Save(strSaveFilePath, ImageFormat.Png);
thumbNailImg.Dispose();
}
catch (Exception ObjException)
{
throw new Exception(ObjException.Message.ToString());
}

}



tag-Upload and Resize Image in the Asp.net Using C#.Net .
Resize image ,Upload Image in VS 2005