■■图片克隆问题,帮忙帮忙,解决不了!■■ [C#][Serializable]public delegate bool Image.GetThumbnailImageAbort();可以 new 的吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 希望下面代码对你有用:/// <summary> /// 建立一个新的商品并上传商品图片和缩略图,如果数据库中已有该商品名,返回的布尔值为false。 /// </summary> /// <param name="pI">商品信息</param> /// <param name="upFile">HtmlInputFile类对象</param> /// <param name="sitePhyAddr">文件目录的物理路径</param> public bool Create(ProductInfo pI, HtmlInputFile upFile, string sitePhyAddr) { // 得到文件后缀,并转换为小写 string fileName = upFile.PostedFile.FileName; string fileFix = fileName.Substring(fileName.LastIndexOf('.') + 1);// 得到文件后缀 fileFix = fileFix.ToLower();//转换为小写字符。 int id = GetMaxId(); string idNow; id++; idNow = id.ToString(); // 判断用户是否选择了商品图 if (fileName != "") { // 如果用户上传后缀合法则进行上传照片和缩略图 if (fileFix == "jpg" || fileFix == "gif" ) { // 上传照片原图 string pathName = @"\Photo\" + idNow + "." + fileFix; string fullName = sitePhyAddr + pathName; string bPathName = @"\BreviaryPhoto\" + idNow + "." + fileFix; string bFullName = sitePhyAddr + bPathName; // 缩小图完整物理路径 upFile.PostedFile.SaveAs(fullName); // 上传照片缩略图 decimal width; decimal height; int newWidth; int newHeight; pathName = @"\Photo\" + idNow + "." + fileFix; System.Drawing.Image image = System.Drawing.Image.FromFile(fullName); System.Drawing.Image smallImage; width = image.Width; height = image.Height; // 如果图片宽大于高,则图片按预定宽度成比例缩放高度 if (width > height) { newWidth = settings.ProductsBreviaryImageWidth; newHeight = (int) (height / width * newWidth); } else { // 否则图片按预定高度成比例缩放宽度 newHeight = settings.ProductsBreviaryImageHeight; newWidth = (int) (width / height * newHeight); } try { smallImage = image.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero); } catch(Exception ex) { image.Dispose(); throw ex; } // 根据类型保存缩略图 switch (fileFix) { case "jpg": smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Jpeg); break; case "gif": smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Gif); break; } smallImage.Dispose(); image.Dispose(); } else { throw new Exception("上传的图片后缀不合法"); } } else { // 指向表示暂时没有商品的图片 idNow = "0"; fileFix = "gif"; } // 数据库中创建商品 DataLayer.Products prd = new DataLayer.Products(settings.SqlConnString); pI.PictureAddr = "Photo/" + idNow + "." + fileFix; pI.BreviaryPictureAddr = "BreviaryPhoto/" + idNow + "." + fileFix; return prd.Create(pI); } 呵呵,我不懂的说.看MSDN的例子说 public bool ThumbnailCallback(){return false;}public void Example_GetThumb(PaintEventArgs e){Image.GetThumbnailImageAbort myCallback =new Image.GetThumbnailImageAbort(ThumbnailCallback);Bitmap myBitmap = new Bitmap("Climber.jpg");Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);e.Graphics.DrawImage(myThumbnail, 150, 75);} 搂主,别的不说,我再98下,不能做实验测试一下,首先page_load里面的参数 EventArgs e和PaintEventArgs e是不一样的,后面的这一个可以这么e.Graphics引用,而前面的就不行了.这应该是一个问题,其他问题可能还存在,有些东西是不能直接由winform转移到webform得 open flash chart关于asp.net的教程 一个正则问题 提问 根据复选框的选择来删除数据 想询问一下大家都用什么样的js库 请问,JSP创建的COOKIE我用ASP.net怎样读取啊 Asp.Net系统刷新页面频繁出错,寻求帮助。 残呐,天啊!Visual Studio.NET已检测到指定的Web服务器运行的不是ASP.NET1.1版,怎么办? 在datagrid中模板用dropdownlist控件 数据绑定问题。 问题多多,难易都有。请各位朋友帮帮忙! 一个非常小的问题 请大家帮忙 cookie中保存用户密码是否安全,如果不保存不验证密码是否安全?
/// 建立一个新的商品并上传商品图片和缩略图,如果数据库中已有该商品名,返回的布尔值为false。
/// </summary>
/// <param name="pI">商品信息</param>
/// <param name="upFile">HtmlInputFile类对象</param>
/// <param name="sitePhyAddr">文件目录的物理路径</param>
public bool Create(ProductInfo pI, HtmlInputFile upFile, string sitePhyAddr)
{
// 得到文件后缀,并转换为小写
string fileName = upFile.PostedFile.FileName;
string fileFix = fileName.Substring(fileName.LastIndexOf('.') + 1);// 得到文件后缀
fileFix = fileFix.ToLower();//转换为小写字符。
int id = GetMaxId();
string idNow; id++;
idNow = id.ToString();
// 判断用户是否选择了商品图
if (fileName != "")
{
// 如果用户上传后缀合法则进行上传照片和缩略图
if (fileFix == "jpg" || fileFix == "gif" )
{
// 上传照片原图
string pathName = @"\Photo\" + idNow + "." + fileFix;
string fullName = sitePhyAddr + pathName;
string bPathName = @"\BreviaryPhoto\" + idNow + "." + fileFix;
string bFullName = sitePhyAddr + bPathName; // 缩小图完整物理路径 upFile.PostedFile.SaveAs(fullName);
// 上传照片缩略图
decimal width;
decimal height;
int newWidth;
int newHeight; pathName = @"\Photo\" + idNow + "." + fileFix;
System.Drawing.Image image = System.Drawing.Image.FromFile(fullName);
System.Drawing.Image smallImage;
width = image.Width;
height = image.Height; // 如果图片宽大于高,则图片按预定宽度成比例缩放高度
if (width > height)
{
newWidth = settings.ProductsBreviaryImageWidth;
newHeight = (int) (height / width * newWidth);
}
else
{
// 否则图片按预定高度成比例缩放宽度
newHeight = settings.ProductsBreviaryImageHeight;
newWidth = (int) (width / height * newHeight);
}
try
{
smallImage = image.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
}
catch(Exception ex)
{
image.Dispose();
throw ex;
} // 根据类型保存缩略图
switch (fileFix)
{
case "jpg":
smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "gif":
smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Gif);
break;
} smallImage.Dispose();
image.Dispose();
}
else
{
throw new Exception("上传的图片后缀不合法");
}
}
else
{
// 指向表示暂时没有商品的图片
idNow = "0";
fileFix = "gif";
} // 数据库中创建商品
DataLayer.Products prd = new DataLayer.Products(settings.SqlConnString);
pI.PictureAddr = "Photo/" + idNow + "." + fileFix;
pI.BreviaryPictureAddr = "BreviaryPhoto/" + idNow + "." + fileFix; return prd.Create(pI);
}
看MSDN的例子说 public bool ThumbnailCallback(){return false;}public void Example_GetThumb(PaintEventArgs e){Image.GetThumbnailImageAbort myCallback =new Image.GetThumbnailImageAbort(ThumbnailCallback);Bitmap myBitmap = new Bitmap("Climber.jpg");Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);e.Graphics.DrawImage(myThumbnail, 150, 75);}
page_load里面的参数 EventArgs e和PaintEventArgs e是不一样的,后面的这一个可以这么e.Graphics引用,而前面的就不行了.
这应该是一个问题,其他问题可能还存在,有些东西是不能直接由winform转移到webform得