Tuesday, April 21, 2009

ResizeImage From source path to destination path

public void ResizeImage(string sourFilePath, int MaxSideSize, string destFilePath)
{
System.Drawing.Image imgInput = System.Drawing.Image.FromFile(sourFilePath);
int intNewWidth;
int intNewHeight;

//Determine image format
ImageFormat fmtImageFormat = imgInput.RawFormat;

//get image original width and height
int intOldWidth = imgInput.Width;
int intOldHeight = imgInput.Height;

//determine if landscape or portrait
int intMaxSide;

if (intOldWidth >= intOldHeight)
{
intMaxSide = intOldWidth;
}
else
{
intMaxSide = intOldHeight;
}
if (intMaxSide > MaxSideSize)
{
//set new width and height
double dblCoef = MaxSideSize / (double)intMaxSide;
intNewWidth = Convert.ToInt32(dblCoef * intOldWidth);
intNewHeight = Convert.ToInt32(dblCoef * intOldHeight);
}
else
{
intNewWidth = intOldWidth;
intNewHeight = intOldHeight;
}
//create new bitmap
Bitmap bmpResized = new Bitmap(imgInput, intNewWidth, intNewHeight);

bmpResized.Save(destFilePath, ImageFormat.Jpeg);
}

Extract Zip file

using java.util;
using java.util.zip;
using java.io;

private void Extract(string zipFileNamePath, string destinationPath)
{
ZipFile zipfile = new ZipFile(zipFileNamePath);
List zipFiles = GetZipFiles(zipfile);

foreach (ZipEntry zipFile in zipFiles)
{
if (!zipFile.isDirectory())
{
InputStream s = zipfile.getInputStream(zipFile);
try
{
Directory.CreateDirectory(destinationPath + "\\");
FileOutputStream dest = new FileOutputStream(Path.Combine(destinationPath + "\\", Path.GetFileName(zipFile.getName())));
try
{
int len = 0;
sbyte[] buffer = new sbyte[8000];
while ((len = s.read(buffer)) >= 0)
{
dest.write(buffer, 0, len);
}
}
catch (Exception ex)
{
dest.close();
s.close();
}
finally
{
dest.close();
}
dest.close();
}
catch (Exception ex)
{
s.close();
}
finally
{
s.close();
}
s.close();
}
}
zipfile.close();
}