王朝网络
分享
 
 
 

一个VB.NET写的简单图片缩放处理组件源代码,支持添加半透明效果小图标

王朝vb·作者佚名  2006-01-09
宽屏版  字体: |||超大  

VB.NET写的一个图片处理组件,用于在ASP中处理图片,缩放图片,成比例缩放,有固定比例背景的缩放,加半透明LOGO小图标等功能.

dImage.vb

Imports System

Imports System.Drawing

<ComClass(dImage.ClassId, dImage.InterfaceId, dImage.EventsId)> _

Public Class dImage

#Region "COM GUIDs"

' 这些 GUID 提供该类的 COM 标识及其 COM 接口。

' 如果您更改它们,现有的客户端将再也无法

' 访问该类。

Public Const ClassId As String = "29641F37-8FA4-4ED9-9118-9DA8EFA306B9"

Public Const InterfaceId As String = "06E4B037-2461-4F83-96BE-2A5D1CAAB0CE"

Public Const EventsId As String = "802EBB14-2D4D-416E-BA26-E8ADCD480E26"

#End Region

' 可创建的 COM 类必须具有不带参数的

' Public Sub New(),否则,该类将不会注册到 COM 注册表中,

' 而且不能通过 CreateObject

' 来创建。

Private myImage As Drawing.Bitmap

Private syimg As Drawing.Bitmap

Private syok As Boolean = False

Private myok As Boolean = False

Public Sub New()

MyBase.New()

End Sub

Public WriteOnly Property bigImage() As String

Set(ByVal Value As String)

Try

myImage = New Bitmap(Value)

myok = True

Catch e As IO.IOException

myok = False

End Try

End Set

End Property

Public WriteOnly Property LogoImage() As String

Set(ByVal Value As String)

Try

syimg = New Bitmap(Value)

syok = True

Catch ex As Exception

syok = False

End Try

End Set

End Property

Public Function SaveAs(ByVal ToFile As String, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal nLogo As Boolean) As String

Try

If myok = False Then

Return "err0"

Exit Function

End If

Dim newbmp As Bitmap = New Bitmap(nWidth, nHeight, Imaging.PixelFormat.Format16bppArgb1555)

Dim iX As Integer

Dim iY As Integer

Dim xMax As Integer

Dim yMax As Integer

For iX = 0 To nWidth - 1

For iY = 0 To nHeight - 1

newbmp.SetPixel(iX, iY, Color.White)

Next

Next

If nWidth < myImage.Width Or nHeight < myImage.Height Then

If myImage.Width / myImage.Height > nWidth / nHeight Then

xMax = nWidth

yMax = myImage.Height * nWidth \ myImage.Width

Else

yMax = nHeight

xMax = myImage.Width * nHeight \ myImage.Height

End If

Else

xMax = myImage.Width

yMax = myImage.Height

End If

Dim tembmp As Bitmap = New Bitmap(myImage, xMax, yMax)

xMax = (newbmp.Width - tembmp.Width) \ 2

yMax = (newbmp.Height - tembmp.Height) \ 2

For iX = 0 To tembmp.Width - 1

For iY = 0 To tembmp.Height - 1

newbmp.SetPixel(iX + xMax, iY + yMax, tembmp.GetPixel(iX, iY))

Next

Next

If syok And nLogo Then

Dim cob As Color

Dim coc As Color

xMax = newbmp.Width - syimg.Width - 4

yMax = newbmp.Height - syimg.Height - 3

For iX = 0 To syimg.Width - 1

For iY = 0 To syimg.Height - 1

cob = syimg.GetPixel(iX, iY)

coc = newbmp.GetPixel(iX + xMax, iY + yMax)

newbmp.SetPixel(iX + xMax, iY + yMax, getnewco(cob, coc))

Next

Next

End If

newbmp.Save(ToFile, Imaging.ImageFormat.Jpeg)

newbmp.Dispose()

tembmp.Dispose()

newbmp = Nothing

tembmp = Nothing

Return "OK"

Catch ex As Exception

Return ex.ToString

End Try

End Function

Public ReadOnly Property Width() As Integer

Get

Return myImage.Width

End Get

End Property

Public ReadOnly Property Height() As Integer

Get

Return myImage.Height

End Get

End Property

Public Sub Close()

myImage.Dispose()

syimg.Dispose()

myImage = Nothing

syimg = Nothing

End Sub

Private Function getnewco(ByVal c1 As Color, ByVal c2 As Color) As Color

Dim a1 As Integer = c1.A

Dim r1 As Integer = c1.R

Dim g1 As Integer = c1.G

Dim b1 As Integer = c1.B

Dim a2 As Integer = c2.A

Dim r2 As Integer = c2.R

Dim g2 As Integer = c2.G

Dim b2 As Integer = c2.B

a2 = 255 - a1

r1 = CInt((r1 * a1 / 255) + (r2 * a2 / 255))

g1 = CInt((g1 * a1 / 255) + (g2 * a2 / 255))

b1 = CInt((b1 * a1 / 255) + (b2 * a2 / 255))

Return Color.FromArgb(a1, r1, g1, b1)

End Function

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有