国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

VB.NET簡單圖片縮放處理組件源代碼,支持添加半透明效果小圖標

2024-07-10 13:05:22
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 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


    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 上栗县| 开鲁县| 长岛县| 双牌县| 平江县| 芮城县| 沂南县| 株洲市| 增城市| 黄冈市| 霍林郭勒市| 广宗县| 浦江县| 石棉县| 崇阳县| 巴马| 平度市| 朝阳区| 扶沟县| 滦南县| 沙雅县| 米脂县| 科技| 平遥县| 贵德县| 酒泉市| 怀安县| 达州市| 舒城县| 喀什市| 西华县| 天水市| 巧家县| 衢州市| 长子县| 靖远县| 寿宁县| 高碑店市| 荔浦县| 成安县| 西峡县|