Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

2010年10月22日 星期五

用Asp.net產生縮圖及浮水印

最近因實務上的需要,尋找相關的技術
剛好看到這篇文章,先記下,再慢慢研究

源自以下網址
http://www.dotblogs.com.tw/jameswu/archive/2008/04/22/3046.aspx


Imports System.IO
Imports System.Drawing.Imaging

Sub Button1_ServerClick(sender As Object, e As System.EventArgs) '
Dim g As Graphics = Nothing
Dim upimage As System.Drawing.Image = Nothing
Dim thumimg As System.Drawing.Image = Nothing
Dim simage As System.Drawing.Image = Nothing
Dim outputfile As Bitmap = Nothing
Try
Dim extension As String = Path.GetExtension(File1.PostedFile.FileName).ToUpper()
Dim filename As String = DateTime.Now.ToString("yyyyMMddhhmmss")
Dim smallpath As String = Server.MapPath(".") + "/smallimg/"
Dim bigpath As String = Server.MapPath(".") + "/bigimg/"
Dim width, height, newwidth, newheight As Integer

Dim callb As New System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback)
If Not Directory.Exists(smallpath) Then
Directory.CreateDirectory(smallpath)
End If
If Not Directory.Exists(bigpath) Then
Directory.CreateDirectory(bigpath)
End If
Dim upimgfile As Stream = File1.PostedFile.InputStream
Dim simagefile As String = Server.MapPath("MyPic.jpg") '要加浮水印的文件
simage = System.Drawing.Image.FromFile(simagefile)
upimage = System.Drawing.Image.FromStream(upimgfile) '上傳的圖片
width = upimage.Width
height = upimage.Height
If width > height Then
newwidth = 200
newheight = CInt(CDbl(height) / CDbl(width) * CDbl(newwidth))
Else
newheight = 200
newwidth = CInt(CDbl(width) / CDbl(height) * CDbl(newheight))
End If
thumimg = upimage.GetThumbnailImage(newwidth, newheight, callb, IntPtr.Zero)
output

沒有留言:

張貼留言