jayaram

jayaram

  • NA
  • 83
  • 36.7k

Image compression in the form of JPEG2000

Mar 11 2011 4:50 AM
Hi all,

I want to compress the images in the form of JPEG2000
and maximum size is 150(height, width) by using aspect ratio,
and I want to reduce the image to 1kb (maximum 1100 bytes) 

I have written in the following way , In this case I got aspect ration properly but
I got image size to 4 to 5 kb 
1)How to reduce this size to 1kb (maximum 1100 bytes) .
2)I must use maximum size is 150(height, width)

Please send me code for these two questions.

My code is :


public void Resize(Image originalImage)
{
int targetHeight, targetWidth,targetsize=150;
if(originalImage.Height>originalImage.Width)
{
targetHeight = targetSize;
targetWidth = (int)(originalImage.Width * ((float)targetSize / (float)originalImage.Height));
}
else
{
targetWidth = targetSize;
targetHeight = (int)(originalImage.Height * ((float)targetSize / (float)originalImage.Width));
}
Bitmap newImage = new Bitmap(originalImage, targetWidth, targetHeight);
Graphics g = Graphics.FromImage(newImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);
originalImage.Dispose();

newImage.Save(@"D:\Images\hello.j2k", System.Drawing.Imaging.ImageFormat.Jpeg);
}


3)How to upload this compressed image in byte format ?

please send me answers for above three questions ...

Thank you



Answers (4)