All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在ASP.NET,2.0中使用RDLC格式的报表的问题_.net资料_编程技术
PHP中使用XML-RPC构造Web,Service简单入门_php资料_编程技术
ASP.NET,Forums,页面模型分析_.net资料_编程技术
SQL,Server,2008,R2官方上市日期出炉_mssql学习_编程技术
动态网页技术PHP的数组处理函数库_[PHP教程]
SqlServer2000获取当前日期及格式_[SQL Server教程]
整理显示照片exif信息_[PHP教程]
PHP学习宝典-第八章(二)_[PHP教程]
C#中加强ListView控件的功能_[Asp.Net教程]
将多次查询的数据填充到同一数据源_.net资料_编程技术
Reading number is top 10 pictures
男人帮杂志里的惹火性感美女2
NeedWallpaper7
BingBingFan apple dew point photo gallery4
The money of more than 100 countries and regions1
Other people's teacher VS my teacher
29 the belle stars after bath figure5
俞敏洪在清华终于说了实话
In 2013 hercules Arnold classic2
妹子最好别玩单反
Sora aoi possession photo1
Download software ranking
Eclipse 4.2.2 For Win32
Sora aoi's film--cangkong_Blue.Sky
仙剑奇侠传98硬盘WINXP版
Boxer's Top ten classic battle9
Boxer vs Yellow5
Tram sex maniac 2 (H) rar bag15
c#程序设计案例教程
Unix video tutorial15
Professional killers2 data package
Unix video tutorial8
归海一刀 published in(发表于) 2014/1/30 1:24:07 Edit(编辑)
asp.net缩略图和水印制作-Image,Generation_[Asp.Net教程]

asp.net缩略图和水印制作-Image,Generation_[Asp.Net教程]

asp.net缩略图和水印制作:Image Generation_[Asp.Net教程]
asp.net Image Generation内置了ImageResizeTransform类,可以实现图片大小调整功能。
也可以扩展ImageTransform实现自己的图片变换类。
下面使用ASP.NET Image Generation生成图片缩略图及水印的代码:

数据库
CREATE TABLE t_images
(
image_id INT,
image_data IMAGE,
last_modified_date, DATETIME
)

Default.aspx

Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NET35Lab.GeneratedImage.Web._Default" %>

<%@ Register Assembly="Microsoft.Web.GeneratedImage" Namespace="Microsoft.Web" TagPRefix="cc1" %>









RepeatDirection="Horizontal" CellPadding="4" CellSpacing="4">

Timestamp=’<%# Eval("last_modified_date") %>’>

’ />








ProviderName="System.Data.SqlClient" SelectCommand="SELECT [image_id], [image_data], [last_modified_date] FROM [t_images]">





ImageHandler1.ashx

<%@ WebHandler Language="C#" CodeBehind="ImageHandler1.ashx.cs" Class="NET35Lab.GeneratedImage.Web.ImageHandler1" %>

ImageHandler1.ashx.cs

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Web;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.Drawing;

namespace NET35Lab.GeneratedImage.Web
{

public class ImageHandler1 : ImageHandler
{

public ImageHandler1()
{
this.ImageTransforms.Add(new ImageResizeTransform { Width = 320, Mode = ImageResizeMode.Fit });
this.ImageTransforms.Add(new CopyrightTransform { Text = "Guushuuse .NET" });
this.EnableClientCache = true;
this.EnableServerCache = true;

}

public override ImageInfo GenerateImage(NameValueCollection parameters)
{

int imageID = int.Parse(parameters["imageid"]);

SqlConnection connection = new SqlConnection(
@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;");

connection.Open();

SqlCommand command = new SqlCommand("select image_data from t_images where image_id=" + imageID, connection);

SqlDataReader dr = command.ExecuteReader();

dr.Read();

return new ImageInfo((Byte[])dr[0]);

}
}

public class CopyrightTransform : ImageTransform
{
private const int VERTICAL_PADDING = 5;
private const int HORIZONAL_PADDING = 5;

public string Text { get; set; }
public Font Font { get; set; }
public Color FontColor { get; set; }

public CopyrightTransform()
{
//Assign Defaults
FontColor = Color.FromArgb(128, 255, 0, 0);
Font = new Font("Courier", 13);
}


public override System.Drawing.Image ProcessImage(System.Drawing.Image img)
{
Graphics gra = Graphics.FromImage(img);
SizeF sz = gra.MeasureString(Text, Font);
gra.DrawString(Text, Font, new SolidBrush(FontColor), img.Width - sz.Width - HORIZONAL_PADDING, img.Height - sz.Height - VERTICAL_PADDING);
return img;
}

public override string UniqueString
{
get
{
return base.UniqueString + Text + FontColor.ToString() + Font.ToString();
}
}
}
}


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.