請參考來源:<< Serial Port 系列(10) 基本篇 -- DataReceived Event 簡易應對方針 | Home | Serial Port 系列(12) 基本篇 -- 完整接收資料(一) >>
--
這兒十多篇相關 Serial Port , 可參考一下唷!
2015年7月9日 星期四
2015年7月6日 星期一
2015年7月4日 星期六
ASP.NET 即時產生縮圖
參考引用來源:[ASP.NET] 即時產生縮圖
--
需求:傳入圖片網址,產生即時縮圖。
可依需求做在一隻檔案裡面 .. 有需要就傳值給它去處理。 (這隻檔案 ContentType 會是 image/Jpeg)
需 Import 進下列 Namespace:
Imports System.Drawing
Imports System.Net
Imports System.IO
Imports System.Web
'''
''' 不儲存縮圖的即時繪製縮圖方法
'''
''' 圖檔網址
''' 寬
''' 高
'''
'''
Public Function renderThumb(ByVal durl As String, ByVal w As Integer, ByVal h As Integer)
Dim width, height As Integer
Dim wc As WebClient = New WebClient()
Dim ms As MemoryStream = New MemoryStream(wc.DownloadData(durl))
Dim image As System.Drawing.Image = New Bitmap(ms)
width = image.Width
height = image.Height
If Not (width < w And height < h) Then
If width > height Then
h = w * height / width
Else
w = h * width / height
End If
End If
Dim img As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
Dim graphic As Graphics = Graphics.FromImage(img)
graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphic.DrawImage(image, 0, 0, w, h)
image.Dispose()
Dim ms_r As New System.IO.MemoryStream()
img.Save(ms_r, System.Drawing.Imaging.ImageFormat.Jpeg)
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "image/Jpeg"
HttpContext.Current.Response.BinaryWrite(ms_r.ToArray())
img.Dispose()
graphic.Dispose()
End Function
--
需求:傳入圖片網址,產生即時縮圖。
可依需求做在一隻檔案裡面 .. 有需要就傳值給它去處理。 (這隻檔案 ContentType 會是 image/Jpeg)
需 Import 進下列 Namespace:
Imports System.Drawing
Imports System.Net
Imports System.IO
Imports System.Web
'''
''' 不儲存縮圖的即時繪製縮圖方法
'''
''' 圖檔網址
''' 寬
''' 高
'''
'''
Public Function renderThumb(ByVal durl As String, ByVal w As Integer, ByVal h As Integer)
Dim width, height As Integer
Dim wc As WebClient = New WebClient()
Dim ms As MemoryStream = New MemoryStream(wc.DownloadData(durl))
Dim image As System.Drawing.Image = New Bitmap(ms)
width = image.Width
height = image.Height
If Not (width < w And height < h) Then
If width > height Then
h = w * height / width
Else
w = h * width / height
End If
End If
Dim img As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
Dim graphic As Graphics = Graphics.FromImage(img)
graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphic.DrawImage(image, 0, 0, w, h)
image.Dispose()
Dim ms_r As New System.IO.MemoryStream()
img.Save(ms_r, System.Drawing.Imaging.ImageFormat.Jpeg)
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "image/Jpeg"
HttpContext.Current.Response.BinaryWrite(ms_r.ToArray())
img.Dispose()
graphic.Dispose()
End Function
2015年7月2日 星期四
2015年7月1日 星期三
asp.net 動態產生CheckBox
參考引用來源
--
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Partial Class Default4
Inherits System.Web.UI.Page
Private WorkMch As String() = {"A", "B", "C", "D", "E", "F", _
"G", "H"}
'CheckBox的Text
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Page.Load
If Not IsPostBack Then
AddControls()
End If
End Sub
Protected Overrides Sub LoadViewState(savedState As Object)
MyBase.LoadViewState(savedState)
'ViewState["controsladded"]似乎是由base繼承下來的,不可更改
If ViewState("controsladded") Is Nothing Then
AddControls()
End If
End Sub
Private Sub AddControls()
pnlCheckbox.Controls.Add(New LiteralControl("
Dim i As Integer = 0
While i < WorkMch.Length
Dim l_cbx As New CheckBox()
l_cbx.Text = WorkMch(i).ToString()
l_cbx.ID = "cbx" + WorkMch(i).ToString()
l_cbx.AutoPostBack = True
'pnlCheckbox為Panel控制項
pnlCheckbox.Controls.Add(New LiteralControl(""))
pnlCheckbox.Controls.Add(l_cbx)
pnlCheckbox.Controls.Add(New LiteralControl("
"))
If i > 0 AndAlso i Mod 4 = 3 AndAlso i <> WorkMch.Length - 1 Then
pnlCheckbox.Controls.Add(New LiteralControl("
"))
ElseIf i = WorkMch.Length - 1 Then
pnlCheckbox.Controls.Add(New LiteralControl("
")) End If
'為自訂的checkbox掛上event
AddHandler l_cbx.CheckedChanged, New EventHandler(AddressOf(l_cbx_CheckedChanged))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
pnlCheckbox.Controls.Add(New LiteralControl("
")) ViewState("controlsadded") = True
End Sub
Private Sub l_cbx(sender As Object, e As System.EventArgs) Handles l.cbx
Dim cbx As CheckBox = CType(sender, CheckBox)
Response.Write("CheckBox" + cbx.Text + " : " + cbx.Checked.ToString())
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim cbxA As New CheckBox()
cbxA = CType(pnlCheckbox.FindControl("cbxA"), CheckBox)
Response.Write(cbxA.Checked)
End Sub
Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
pnlCheckbox.Controls.Clear()
End Sub
End Class
--
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Partial Class Default4
Inherits System.Web.UI.Page
Private WorkMch As String() = {"A", "B", "C", "D", "E", "F", _
"G", "H"}
'CheckBox的Text
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Page.Load
If Not IsPostBack Then
AddControls()
End If
End Sub
Protected Overrides Sub LoadViewState(savedState As Object)
MyBase.LoadViewState(savedState)
'ViewState["controsladded"]似乎是由base繼承下來的,不可更改
If ViewState("controsladded") Is Nothing Then
AddControls()
End If
End Sub
Private Sub AddControls()
pnlCheckbox.Controls.Add(New LiteralControl("
Dim i As Integer = 0
While i < WorkMch.Length
Dim l_cbx As New CheckBox()
l_cbx.Text = WorkMch(i).ToString()
l_cbx.ID = "cbx" + WorkMch(i).ToString()
l_cbx.AutoPostBack = True
'pnlCheckbox為Panel控制項
pnlCheckbox.Controls.Add(New LiteralControl("
pnlCheckbox.Controls.Add(l_cbx)
pnlCheckbox.Controls.Add(New LiteralControl("
"))
If i > 0 AndAlso i Mod 4 = 3 AndAlso i <> WorkMch.Length - 1 Then
pnlCheckbox.Controls.Add(New LiteralControl("
pnlCheckbox.Controls.Add(New LiteralControl("
")) End If
'為自訂的checkbox掛上event
AddHandler l_cbx.CheckedChanged, New EventHandler(AddressOf(l_cbx_CheckedChanged))
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
pnlCheckbox.Controls.Add(New LiteralControl("
")) ViewState("controlsadded") = True
End Sub
Private Sub l_cbx(sender As Object, e As System.EventArgs) Handles l.cbx
Dim cbx As CheckBox = CType(sender, CheckBox)
Response.Write("CheckBox" + cbx.Text + " : " + cbx.Checked.ToString())
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim cbxA As New CheckBox()
cbxA = CType(pnlCheckbox.FindControl("cbxA"), CheckBox)
Response.Write(cbxA.Checked)
End Sub
Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
pnlCheckbox.Controls.Clear()
End Sub
End Class
訂閱:
文章 (Atom)