hallo zusammen
weiss jemand ob es möglich ist ein bild in einer picturebox durchscheinend zu machen? Ich will den Hintergrund durchscheinen lassen. Ich verwende visual studio 2008.
Danke
Druckbare Version
hallo zusammen
weiss jemand ob es möglich ist ein bild in einer picturebox durchscheinend zu machen? Ich will den Hintergrund durchscheinen lassen. Ich verwende visual studio 2008.
Danke
also, du kannst entweder ein ELEMENT.BackColor = transparent versuchen.
andernfalls kannst du auch ein bitmap laden, welches einen transparenten hintergrund enthält (die palette muss entsprechend sein, gibt es ein extra menü dafür).
oder aber diese Funktion (frei nach CodeGuru (Englisch)) verwenden:
die Funktion maskiert ein bild, kopiert es in ein zweites und entfernt die maske. Wenn du nur eine maske entfernen willst, sollte das aber so auch machbar sein.Code:Sub TransparentBlt(dsthDC As Long, srchDC As Long, X As Integer, _
Y As Integer, Width As Integer, _
Height As Integer, TransColor As Long)
Dim maskDC As Long 'DC for the mask
Dim tempDC As Long 'DC for temporary data
Dim hMaskBmp As Long 'Bitmap for mask
Dim hTempBmp As Long 'Bitmap for temporary data
'First, create some DC's. These are our gateways to associated
'bitmaps in RAM
maskDC = CreateCompatibleDC(dsthDC)
tempDC = CreateCompatibleDC(dsthDC)
'Then, we need the bitmaps. Note that we create a monochrome
'bitmap here!
'This is a trick we use for creating a mask fast enough.
hMaskBmp = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
hTempBmp = CreateCompatibleBitmap(dsthDC, Width, Height)
'Then we can assign the bitmaps to the DCs
hMaskBmp = SelectObject(maskDC, hMaskBmp)
hTempBmp = SelectObject(tempDC, hTempBmp)
'Now we can create a mask. First, we set the background color
'to the transparent color; then we copy the image into the
'monochrome bitmap.
'When we are done, we reset the background color of the
'original source.
TransColor = SetBkColor(srchDC, TransColor)
BitBlt maskDC, 0, 0, Width, Height, srchDC, 0, 0, vbSrcCopy
TransColor = SetBkColor(srchDC, TransColor)
'The first we do with the mask is to MergePaint it into the
'destination.
'This will punch a WHITE hole in the background exactly were
'we want the graphics to be painted in.
BitBlt tempDC, 0, 0, Width, Height, maskDC, 0, 0, vbSrcCopy
BitBlt dsthDC, X, Y, Width, Height, tempDC, 0, 0, vbMergePaint
'Now we delete the transparent part of our source image. To do
'this, we must invert the mask and MergePaint it into the
'source image. The transparent area will now appear as WHITE.
BitBlt maskDC, 0, 0, Width, Height, maskDC, 0, 0, vbNotSrcCopy
BitBlt tempDC, 0, 0, Width, Height, srchDC, 0, 0, vbSrcCopy
BitBlt tempDC, 0, 0, Width, Height, maskDC, 0, 0, vbMergePaint
'Both target and source are clean. All we have to do is to AND
'them together!
BitBlt dsthDC, X, Y, Width, Height, tempDC, 0, 0, vbSrcAnd
'Now all we have to do is to clean up after us and free system
'resources..
DeleteObject (hMaskBmp)
DeleteObject (hTempBmp)
DeleteDC (maskDC)
DeleteDC (tempDC)
End Sub
Link zu einem Beispiel mit dem AlphaBlend API im zweiten Posting und eine einfache Art im dritten Posting.
http://forums.microsoft.com/MSDN/Sho...76600&SiteID=1
Danke euch für die Antworten. Werde demnächst versuchen die Sache zu Ende zu bringen und den hoffentlichen Erfolg posten :cool: