mirahsani
جمعه 06 دی 1392, 12:23 عصر
سلام دوستان
من از تامبنیل برای تصاویر گالری استفاده می کنم. ولی تار و کمی شطرنجی میشن. کدهایی که استفاده می کنم در زیر قرار میدم. شما کدهای بهتری سراغ ندارید؟
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace asiaamp_english
{
/// <summary>
/// Creates a thumbnail image from a file spec in the calling URL.
/// </summary>
public partial class MakeThumbnail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
int i = Convert.ToInt32(Request.QueryString["i"]);
int j = Convert.ToInt32(Request.QueryString["j"]);
string file = Request.QueryString["file"];
using (System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file) ))
{
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(i, j, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
MemoryStream imageStream = new MemoryStream();
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageContent = new byte[imageStream.Length];
imageStream.Position = 0;
imageStream.Read(imageContent, 0, (int)imageStream.Length);
Response.ContentType = "image/png";
Response.BinaryWrite(imageContent);
}
}
catch { }
}
public bool ThumbnailCallback()
{
return true;
}
// public System.Drawing.Image.GetThumbnailImageAbort ThumbnailCallBack { get; set; }
}
}
من از تامبنیل برای تصاویر گالری استفاده می کنم. ولی تار و کمی شطرنجی میشن. کدهایی که استفاده می کنم در زیر قرار میدم. شما کدهای بهتری سراغ ندارید؟
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace asiaamp_english
{
/// <summary>
/// Creates a thumbnail image from a file spec in the calling URL.
/// </summary>
public partial class MakeThumbnail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
int i = Convert.ToInt32(Request.QueryString["i"]);
int j = Convert.ToInt32(Request.QueryString["j"]);
string file = Request.QueryString["file"];
using (System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file) ))
{
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(i, j, new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback), IntPtr.Zero);
MemoryStream imageStream = new MemoryStream();
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageContent = new byte[imageStream.Length];
imageStream.Position = 0;
imageStream.Read(imageContent, 0, (int)imageStream.Length);
Response.ContentType = "image/png";
Response.BinaryWrite(imageContent);
}
}
catch { }
}
public bool ThumbnailCallback()
{
return true;
}
// public System.Drawing.Image.GetThumbnailImageAbort ThumbnailCallBack { get; set; }
}
}