Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > ASP.NET > ASP.NET Image > ASP.NET Create Thumbnail Image


ASP.NET Create Thumbnail Image

ASP.NET Create Thumbnail Image ตัวอย่างนี้ผมได้เขียน ASP.NET ในการ Resize Thumbnail ทั้งโฟเดอร์

Language Code : VB.NET || C#

Framework : 1,2,3,4

AspNetCreateThumbnail.aspx

01.<%@ Page Language="VB" %>
02.<%@ Import Namespace="System.Drawing" %>
03.<%@ Import Namespace="System.Drawing.Imaging" %>
04.<%@ Import Namespace="System.IO"%>
05.<script runat="server">
06. 
07.    Sub Page_Load(sender As Object, e As EventArgs)
08.        If Not Page.IsPostBack() Then
09.            Me.txtFrom.Text = "Gallery/"
10.            Me.txtTo.Text = "Resize/"
11.        End IF
12.    End Sub
13. 
14.    Sub btnCreate_OnClick(sender As Object, e As EventArgs)
15. 
16.        Dim myDirInfo As DirectoryInfo
17.        Dim arrFileInfo As Array
18.        Dim myFileInfo As FileInfo
19.        Dim FileName As String
20.        Dim NewFileName As String
21. 
22.        Me.lblText.Text = ""
23. 
24.        myDirInfo = New DirectoryInfo(Server.MapPath(Me.txtFrom.Text))     
25.        arrFileInfo = myDirInfo.GetFiles("*.jpg")
26.        For Each myFileInfo In arrFileInfo
27.            FileName = txtFrom.Text & myFileInfo.Name
28.            NewFileName = txtTo.Text & "Thumbnail_"&myFileInfo.Name
29.             
30.            '*** Call to function resize ***'
31.            Call ResizeImages(FileName,NewFileName)
32. 
33.            Me.lblText.Text = Me.lblText.Text & (FileName & "===> <a href=" & NewFileName & ">" & NewFileName &"</a><br>")
34.        Next myFileInfo
35. 
36.    End Sub
37. 
38.    Sub ResizeImages(FileName,NewFileName) 
39.        Dim intWidth,intHeight As Integer
40. 
41.        intWidth =  100 '*** Fix Width ***'
42.        intHeight = 0   '*** If = 0 Auto Re-Cal Size ***'
43. 
44.        Dim objGraphic As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(FileName))
45. 
46.        Dim objBitmap As Bitmap
47.        '*** Calculate Height ***'
48.        If intHeight > 0 Then
49.            objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
50.        Else
51.            If objGraphic.Width > intWidth Then
52.                Dim ratio As Double = objGraphic.Height / objGraphic.Width
53.                intHeight = ratio * intWidth
54.                objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
55.            Else
56.                objBitmap = New Bitmap(objGraphic)
57.            End If
58.        End If
59.         
60.        '*** Save As  ***'
61.        objBitmap.Save(Server.MapPath(NewFileName), objGraphic.RawFormat)
62.         
63.        '*** Close ***'
64.        objGraphic.Dispose()
65.         
66.        '*** Nothing ***'
67.        objBitmap = Nothing
68.        objGraphic = Nothing
69.         
70.    End Sub
71. 
72.</script>
73.<html>
74.<head>
75.<title>ThaiCreate.Com ASP.NET - Images (System.Drawing)</title>
76.</head>
77.<body>
78.    <form id="form1" runat="server">
79.        <asp:Label id="lblForm" runat="server" Text="Path From" Width="58px"></asp:Label>
80.        <asp:Textbox id="txtFrom" runat="server"></asp:Textbox><br />
81.        <asp:Label id="lblTo" runat="server" Text="Path To" Width="58px"></asp:Label>
82.        <asp:Textbox id="txtTo" runat="server"></asp:Textbox>
83.        <input id="btnCreate" type="button" OnServerClick="btnCreate_OnClick"  value="Create" runat="server" />
84.        <hr />
85.        <asp:Label id="lblText" runat="server"></asp:Label>
86.    </form>
87.</body>
88.</html>
89.</form>


Screenshot

ASP.NET Image

ASP.NET Image

ASP.NET Image

   
Hate it
Don't like it
It's ok
Like it
Love it
Total Votes: 601Overall Rating: 3.9 / 5
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-11-28 12:22:07 / 2009-06-03 07:56:31
  Download : Download  ASP.NET Create Thumbnail Image
 Sponsored Links / Related

 
ASP.NET Create Image
Rating :

 
ASP.NET Write Text to Image
Rating :

 
ASP.NET Write Text to Picture
Rating :

 
ASP.NET (Watermark) Upload and Write Text to Picture
Rating :

 
ASP.NET Add Logo/CopyRight to Image
Rating :

 
ASP.NET Upload and Add Logo/CopyRight to Image
Rating :

 
ASP.NET Resize Image
Rating :

 
ASP.NET Upload & Resize Image
Rating :

 
ASP.NET Upload Resize Insert to Database
Rating :

 
ASP.NET Multiple Upload & Multiple Resize
Rating :


ThaiCreate.Com Forum
Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่