System.Drawing.Image.GetThumbnailImageAbort

hongyanhua12 2009-02-10 01:10:48
我对委托不是很清楚,System.Drawing.Image.GetThumbnailImageAbort mycall = new System.Drawing.Image.GetThumbnailImageAbort(bool1);
是怎么用的?能举个简单的例子吗?
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Image.GetThumbnailImageAbort mycall = new System.Drawing.Image.GetThumbnailImageAbort(bool1);
Bitmap image = new Bitmap(Session["filename"].ToString());
System.Drawing.Image image1 = image.GetThumbnailImage(80, 80, mycall, IntPtr.Zero);
image1.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
public bool bool1()
{
return false;
}
...全文
216 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
流年岁月 2009-02-10
  • 打赏
  • 举报
回复
mark 一下
sxmonsy 2009-02-10
  • 打赏
  • 举报
回复
顶一下
宝_爸 2009-02-10
  • 打赏
  • 举报
回复
你的代码就是使用委托的例子啊。委托的意思就是callback。

你可以把mycall 想象成一个函数对象,其构造函数的参数bool1的原型必须符合GetThumbnailImageAbort的声明,把mycall 作为参数传给GetThumbnailImage,在GetThumbnailImage内部会在适当的时候调用bool1。


下面是GetThumbnailImageAbort 的解释,因此你在GetThumbnailImageAbort(其实例的就是mycall) 中可以什么都不做,会不影响GetThumbnailImage的结果。
A Image.GetThumbnailImageAbort delegate. In GDI+ version 1.0, the delegate is not used. Even so, you must create a delegate and pass a reference to that delegate in this parameter.
hongqi162 2009-02-10
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace xmlandasp
{
/// <summary>
/// Summary description for MakeThumbnail.
/// </summary>
public class MakeThumbnail : System.Web.UI.Page
{
/// <summary>
/// Renders the thumbnail the response stream
/// </summary>
private void Page_Load(object sender, System.EventArgs e)
{
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(Request.QueryString["file"]));

System.Drawing.Image thumbNail = image.GetThumbnailImage(100, 80, myCallback, IntPtr.Zero);
Response.ContentType = "image/jpeg";
thumbNail.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
thumbNail.Dispose();
}

/// <summary>
/// Required, but not used
/// </summary>
/// <returns>true</returns>
public bool ThumbnailCallback()
{
return false;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
hongyanhua12 2009-02-10
  • 打赏
  • 举报
回复
帮订一下啊
hongyanhua12 2009-02-10
  • 打赏
  • 举报
回复
什么意思啊?还是不太明白

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧