【asp源码栏目提醒】:网学会员在asp源码频道为大家收集整理了“asp Net_图片上传的一个类库的源码 - 编程语言“提供大家参考,希望对大家有所帮助!
一般情况.图片是不直接存到数据库的.而只是存了图片的名称. 存放图片的文件夹路径一般是固定的. 所以这时你只需要从数据库拿出图片名称.直接在页面中这么写就OK了: 在上传的时候.首先当然是要判断上传文件是不是图片了.不建议去判断文件的后缀名.用这个方法: ifthis.myfile.PostedFile.ContentType.ToString.ToLower.IndexOfimage _MaxSize _Error 3 return try if Directory.Exists_SavePath Directory.CreateDirectory_SavePath byte bData new byteiLen hpFile.InputStream.ReadbData 0 iLen string FName FName FileNameExt string TempFile if _IsDraw TempFileFName.Split..GetValue0.ToString _temp. FName.Split..GetValue1.ToString else TempFile FName FileStream newFile new FileStream_SavePath TempFile FileMode.Create newFile.WritebData 0 bData.Length newFile.Flush int _FileSizeTemp hpFile.ContentLength if _IsDraw if _DrawStyle 0 System.Drawing.Image Img1 System.Drawing.Image.FromStreamnewFile Graphics g Graphics.FromImageImg1 g.DrawImageImg1 100 100 Img1.Width Img1.Height Font f new Font_Font _FontSize Brush b new SolidBrushColor.Red string addtext _AddText g.DrawStringaddtext f b _DrawString_x _DrawString_y g.Dispose Img1.Save_SavePath FName Img1.Dispose else System.Drawing.Image image System.Drawing.Image.FromStreamnewFile System.Drawing.Image copyImage System.Drawing.Image.FromFile_CopyIamgePath Graphics g Graphics.FromImageimage g.DrawImagecopyImage new Rectangleimage.Width - copyImage.Width - 5 image.Height - copyImage.Height - 5 copyImage.Width copyImage.Height 0 0 copyImage.Width copyImage.Height GraphicsUnit.Pixel g.Dispose image.Save_SavePath FName image.Dispose try //获取图片的高度和宽度 System.Drawing.Image Img System.Drawing.Image.FromStreamnewFile _Width Img.Width _Height Img.Height //生成缩略图部分 if _IsCreateImg //如果上传文件小于15k则不生成缩略图。