缩略图不变形
Public Shared Sub MakeSmallImg(ByVal postFile As System.Web.HttpPostedFile, ByVal saveImg As String, ByVal Width As System.Double, ByVal Height As System.Double)
??????? Dim originalFilename As String = postFile.FileName
??????? '生成的高質(zhì)量圖片名稱
??????? Dim strGoodFile As String = saveImg
??????? '從文件取得圖片對(duì)象
??????? Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(postFile.InputStream, True)
??????? Dim NewWidth, NewHeight As System.Double
??????? If (image.Width > image.Height) Then
??????????? NewWidth = Width
??????????? NewHeight = image.Height * (NewWidth / image.Width)
??????? Else
??????????? NewHeight = Height
??????????? NewWidth = (NewHeight / image.Height) * image.Width
??????? End If
??????? If (NewWidth > Width) Then
??????????? NewWidth = Width
??????? End If
??????? If (NewHeight > Height) Then
??????????? NewHeight = Height
??????? End If
??????? '取得圖片大小
??????? Dim size As System.Drawing.Size = New System.Drawing.Size(CType(NewWidth, Integer), CType(NewHeight, Integer))
??????? '新建一個(gè)bmp圖片
??????? Dim bitmap As System.Drawing.Image = New System.Drawing.Bitmap(size.Width, size.Height)
??????? '新建一個(gè)畫(huà)板
??????? Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bitmap)
??????? '設(shè)置高質(zhì)量插值法
??????? g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High
??????? '設(shè)置高質(zhì)量,低速度呈現(xiàn)平滑程度
??????? g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
??????? '清空一下畫(huà)布
??????? g.Clear(Color.White)
??????? '在指定位置畫(huà)圖
??????? g.DrawImage(image, New System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), New System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel)
??????? '文字水印
??????? 'System.Drawing.Graphics G=System.Drawing.Graphics.FromImage(bitmap);
??????? 'System.Drawing.Font f=new Font("宋體",10);
??????? 'System.Drawing.Brush b=new SolidBrush(Color.Black);
??????? 'G.DrawString("myohmine",f,b,10,10);
??????? 'G.Dispose();
?
??????? '圖片水印
??????? 'System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("pic/1.gif"));
??????? 'Graphics a = Graphics.FromImage(bitmap);
??????? 'a.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width,bitmap.Height-copyImage.Height,copyImage.Width, copyImage.Height),0,0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
??????? 'copyImage.Dispose();
??????? 'a.Dispose();
??????? 'copyImage.Dispose();
??????? '保存高清晰度的縮略圖
??????? bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg)
??????? g.Dispose()
??????? image.Dispose()
??????? bitmap.Dispose()
??? End Sub
MakeSmallImg(PhotoPath.PostedFile, filePath, 140, 185)
轉(zhuǎn)載于:https://www.cnblogs.com/kentyshang/archive/2006/11/21/566950.html
總結(jié)
- 上一篇: unity中发布android时候出现这
- 下一篇: 软件测试面试题【2021模拟面试整理版(