Web page shop cart thumbnails are jpeg images with Height='200' MaxWidth='150'
Source jpeg images are big, represented as Byte[] arrays.
Where to find sample code for DrawImage or other solution in server side which reduces size of jpeg Byte[] array for this format and to minimal size before sending ?
kobruleht
Member
589 Points
463 Posts
Convert images to thumbnails
May 05, 2009 04:51 PM|LINK
Web page shop cart thumbnails are jpeg images with Height='200' MaxWidth='150'
Source jpeg images are big, represented as Byte[] arrays.
Where to find sample code for DrawImage or other solution in server side which reduces size of jpeg Byte[] array for this format and to minimal size before sending ?
Andrus.
LiveTecs
Member
566 Points
116 Posts
Re: Convert images to thumbnails
May 05, 2009 08:28 PM|LINK
Here is your solution.
http://www.west-wind.com/Weblog/posts/283.aspx
Thanks
Bug Tracking
Web Timesheet
Time Tracking Software
kobruleht
Member
589 Points
463 Posts
Re: Convert images to thumbnails
May 08, 2009 06:27 PM|LINK
</div></div> <div>I have almost zero experience using System.Drawing </div> <div> </div> <div>I tried to create conversion function using those samples but got 3 strange compile errors shown in comments. </div> <div>How to fix them ?</div> <div> </div> <div>Andrus.</div> <div> </div> <div>// converts jpeg image to jpeg thumbnail</div> <div>Byte[] MakeMeAGoodThumbnail(Byte[] source)
{
// Argument '1': cannot convert from 'byte[]' to 'string'
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(source);
int width, height;
if (bmp.Height > 320 || bmp.Width > 240)
{
float percent = DeterminePercentageForResize(bmp.Height, bmp.Width);
float floatWidth = (float)bmp.Width * percent;
float floatHeight = (float)bmp.Height * percent;</div> <div> </div> <div> width = Convert.ToInt32(floatWidth);
height = Convert.ToInt32(floatHeight);
}
else
{
width = bmp.Width;
height = bmp.Height;
}</div> <div> </div> <div> //Argument '3': cannot convert from 'bool' to 'System.Drawing.Image.GetThumbnailImageAbort' I:\raamat\Eeva\Eeva Business\EntityBase\EntityBase.cs 890 79 Business
System.Drawing.Image thumb = bmp.GetThumbnailImage(width, height, ThumbnailCallback(), IntPtr.Zero);
// Cannot implicitly convert type 'System.Drawing.Bitmap' to 'byte[]'
return new Bitmap(thumb);
}</div> <div> </div> <div> float DeterminePercentageForResize(int height, int width)
{
int highestValue;
if (height > width)
highestValue = height;
else
highestValue = width;</div> <div> </div> <div> float percent = 100 / (float)highestValue;</div> <div> </div> <div> if (percent > 1 && percent != 0)
throw new Exception("Percent cannot be greater than 1 or equal to zero");
else
return percent;
}</div> <div> </div> <div> public bool ThumbnailCallback()
{
return false;
}
</div>