简介
我搜索了很多,一个简单的方法来合并两个位图使用。NET代码。我总是得到发还GDI的BitBlt,这是不友善。NET样式图像。或管理alpha通道。我想我错过了什么... ...?最后,我设计了一个简单的方法适用于任何。NET位图变量的透明度。实际上这并不在真正意义上的两个位图之间的混合颜色,但设置位图,它的透明度百分比应用于位图B,剂量一个不错的工作纹理画笔时使用。
指定正确的矩形,将允许典型的覆盖。这个例子砖覆盖,当您查看屏幕2。这是使用此刷,这是这里没有显示的代码。此代码表示为白色透明度。此代码允许你混合管理alpha通道的位图。
混乱,不保留16万的Windows颜色设置透明色。 Bitmap.MakeTransparent允许您指定的透明色。此代码将分配在一个很好的混合透明的颜色。
这段代码很容易,工程迅速。只要使用此代码作为与bitmap.maketransparency纹理画笔(system.drawing.color.white)位图。Public Sub SetAlphaVary(ByRef abm As Image)
' This code is from DesignLab(C)2007 author Dominic J. Melfi
' It may be used freely as long as the above line is included
=====================================================
' abm is passed as the "Source Image"
' size of source
Dim r1 As RectangleF
r1.X = 0
r1.Y = 0
r1.Width = abm.Width
r1.Height = abm.Height
'
' Set brush into graphics context
graphics1.Dispose()
graphics1 = Graphics.FromImage(abm)
' Dim Path
Dim path1 As New System.Drawing.Drawing2D.GraphicsPath
path1.FillMode = Drawing2D.FillMode.Alternate
path1.AddRectangle(r1)
'Dim brush
' mainform.alphapercent.text argument is 6-17 code for hatch percent
' we are establishing the percent of transparency for our overlay
' actually you cold use any of 52 hatch codes 6-17 are without pattern,
' and represent a percent
' the forecolor is white, and white will be used as transparent color
' when this brush is overlayed
' you could pass the transparent color from the other bitmap
' and the backcolor is transparent which retains origional for these pixels
Dim brush3 As New Drawing2D.HatchBrush _
(CInt(getarg2(MainForm.AlphaPercent.Text, "code")), _
System.Drawing.Color.White, System.Drawing.Color.Transparent)
graphics1.FillPath(brush3, path1)
brush3.Dispose()
path1.Dispose()
' the end result here is you have a brush with a percent of white,
' this is added to any existing white
' that there was, when using this brush declare
' image.maketransparent=system.drawing.color.white
End Sub
下面的图片是从我的项目DesignLab(C)2007。该方案可以管理位图可达7200x7200,并已用于打印出设计大如56quot; x17quot;我Epson7800。我们有印刷设计,以丝绸,丝巾等。
{A1}