I hope this article will help those who need to generate thumbnails frequently!
At present, the Internet has more than 4000 types of products, with more than 20 million products on sale, of which the image volume has been 8 GB so far.
Currently, our solution is to use a separate file server to store product images and access them through file.365goba.com.
On the file server, a WCF Service for uploading images is used to scale down and save uploaded images.
The scaling algorithm at the early stage of the shopping network used the tri-linear interpolation algorithm widely circulated on the network (the effect is not very good). The Code is as follows:
Using System;
Using System. Drawing;
Using System. IO;
Using System. Drawing. Imaging;
Using System. Drawing. Drawing2D;
Namespace Ants. Tools
{
Public class Image
{
Public int Width {get; set ;}
Public int Height {get; set ;}
Private Image (){}
Public Image (int width, int height)
{
This. Width = width;
This. Height = height;
}
Public MemoryStream getHightThumb (Stream imgData, string Mode_HW_W_H_Cut)
{
MemoryStream result = new MemoryStream ();
System. Drawing. Image. GetThumbnailImageAbort myCallBack = new System. Drawing. Image. GetThumbnailImageAbort (ThumbnailCallBack );
Try
{
System. Drawing. Image originalImage = System. Drawing. Image. FromStream (imgData );
Int X, Y;
X = Width;
Y = Height;
Int towidth = X;
Int toheight = Y;
Int x = 0;
Int y = 0;
Int ow = originalImage. Width;
Int oh = originalImage. Height;
Switch (Mode_HW_W_H_Cut)
{
Case "HW": // specify the height/width Scaling (may be deformed) break;
Case "W": // specify the width, and the height is proportional.
Toheight = originalImage. Height * X/originalImage. Width;
Break;
Case "H // specify the Height. The Width is proportional to towidth = originalImage. Width * Y/originalImage. Height;
Break;
Case "Cut ":
If (double) originalImage. Width/(double) originalImage. Height> (double) towidth/(double) toheight)
{
Oh = originalImage. Height;
Ow = originalImage. Height * towidth/toheight;
Y = 0;
X = (originalImage. Width-ow)/2;
}
Else
{
Ow = originalImage. Width;
& N