簡體   English   中英

使圖像透明的 vb.net 代碼

[英]vb.net code to make a image transparent

我希望使用 VB.NET 代碼使位圖圖像 (.bmp) 透明。 請幫助我。

您需要了解有關GDI +(。NET Windows窗體應用程序)的透明度的所有信息。

VS 2012

Dim watermark_bm2 As Bitmap = 'someimage(來自文件或全局資源)

watermark_bm2.MakeTransparent()

我發現關鍵是使用imageAttributes類。 基本上將顏色鍵設置為您用來表示透明區域的顏色,並使用接受imageAttribute參數的drawImage調用之一...

Imports System.Drawing.Imaging

' and in a sub somewhere:

Private mImageAttributes As New ImageAttributes
mImageAttributes.SetColorKey(Color.FromArgb(0, 220, 20, 255), 
Color.FromArgb(0, 220, 20, 255))

Dim imageRectangle As New Rectangle(pX, pY, pBitmap.Width, pBitmap.Height)
e.Graphics.DrawImage(pBitmap, imageRectangle, 0, 0, pBitmap.Width, pBitmap.Height,
GraphicsUnit.Pixel, mImageAttributes)

這篇 msdn 文章提供了有關如何執行此操作的完整詳細信息

這是另一篇文章,但代碼示例是在 c# 中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM