asp.net產生縮圖,打浮水印得類

來源:互聯網
上載者:User
 

asp.net產生縮圖,打浮水印得類,代碼如下:

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace BLL
{
public class ImageUtil
{
public static void addWatermarkImage(Graphics picture, string WaterMarkPicPath, string _watermarkPosition, int _width, int _height)
{
Image image = new Bitmap(WaterMarkPicPath);
int x = 0;
int y = 0;
int width = image.Width;
int height = image.Height;
string str = _watermarkPosition;
if (str != null)
{
if (!(str == "WM_TOP_LEFT"))
{
if (str == "WM_TOP_RIGHT")
{
x = (_width - width) - 10;
y = 10;
}
else if (str == "WM_BOTTOM_RIGHT")
{
x = (_width - width) - 10;
y = (_height - height) - 10;
}
else if (str == "WM_BOTTOM_LEFT")
{
x = 10;
y = (_height - height) - 10;
}
else if (str == "WM_BOTTOM_MIDDLE")
{
x = (_width / 2) - (width / 2);
y = (_height - height) - 10;
}
else if (str == "WM_TOP_MIDDLE")
{
x = (_width / 2) - (width / 2);
y = 10;
}
}
else
{
x = 10;
y = 10;
}
}
picture.DrawImage(image, x, y, width, height);
image.Dispose();
}

public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
{
string str;
Image image = Image.FromFile(originalImagePath);
int num = width;
int num2 = height;
int x = 0;
int y = 0;
int num5 = image.Width;
int num6 = image.Height;
if (((str = mode) != null) && (str != "HW"))
{
if (!(str == "W"))
{
if (str == "H")
{
num = (image.Width * height) / image.Height;
}
else if (str == "Cut")
{
if ((((double)image.Width) / ((double)image.Height)) > (((double)num) / ((double)num2)))
{
num6 = image.Height;
num5 = (image.Height * num) / num2;
y = 0;
x = (image.Width - num5) / 2;
}
else
{
num5 = image.Width;
num6 = (image.Width * height) / num;
x = 0;
y = (image.Height - num6) / 2;
}
}
}
else
{
num2 = (image.Height * width) / image.Width;
}
}
Image image2 = new Bitmap(num, num2);
Graphics graphics = Graphics.FromImage(image2);
graphics.InterpolationMode = InterpolationMode.High;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.Clear(Color.Transparent);
graphics.DrawImage(image, new Rectangle(0, 0, num, num2), new Rectangle(x, y, num5, num6), GraphicsUnit.Pixel);
try
{
image2.Save(thumbnailPath, ImageFormat.Jpeg);
}
catch (Exception exception)
{
throw exception;
}
finally
{
image.Dispose();
image2.Dispose();
graphics.Dispose();
}
}
}

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.