C # clear image scaling Solution

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.