Pictures in VB transparent machen

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/pictures_in_vb_transparent_machen_52848/page_1 - zur Vollversion wechseln!


Hiob schrieb am 25.10.2002 um 13:11

Hi ihr Programmier-Gurus! ;)

Wie schaffe ich es, ein Picture in Visual Basic transparent zu machen. Ich will den grauen Hintergrund wegbringen, sprich transparent machen. Geht das überhaupt?

Mahalo, Hiob


schrieb am 25.10.2002 um 13:31

also ein FORM transparent machen geht nur in VB.NET afaik.


JC schrieb am 25.10.2002 um 13:41

The function you need looks like this: Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long.
What the function does is that it takes a bitmap and cuts out a piece of this bitmap to put into an device context(mostly a picturebox). Now you got a picture in a picturebox.
The last parameter in the function decides how you copy the picture.

Ropecodes
The last parameter in bitblt is the ropecode. This tell you how you will copy the picture. This makes bitblt a very good good animating function because it makes the function very flexible. You can copy the bitmap or you can invert the colors at the same time. You can also paste together several bitmaps. There are many ways that you can use bitblt and the purpose of this site is only to give you the basics of the function so you can try it yourself. Here are some ropecode constants:

Const SRCCOPY = &HCC0020 This will only copy the picture to the destination.
Const SRCINVERT = &H660046 This will copy the picture and invert the colors.
Const SRCPAINT = &HEE0086 This will paint the picture on to the destination.
Const SRCAND = &H8800C6 This will glue a bitamps together with another. Used with masks.

Masks
This a pretty smart way to animate a picture but all bitmaps are rectangular and what will I do if I want another shape? Of course is there a way to us nonrectangeled shapes. It is to use a mask. A mask is a bitmap that contains two colors(normally black/white) I am not 100% sure but I think that the color that are white on the original bitmap must be black on the mask or the opposite. When you got a picture and a mask to that picture you will have to put them together with the bitblt-function by using the ropecode SRCPAINT. Here is a simple example:
BitBlt(pic.bmp, 1,1, pic's width,pic's height, mask.bmp, 1, 1, SRCAND)
BitBlt(pic.bmp, 1,1, pic's width, pic's height, picturebox.hdc, 1, 1, SRCPAINT)

Vielleicht hilft das :)


JC schrieb am 25.10.2002 um 13:44

Das vielleicht bessere Beispiel liefert MS.


Hiob schrieb am 25.10.2002 um 14:13

OK, ich bin für eure Hilfe sehr dankbar, nur ist es nicht ganz das, was ich mir vorgestellt habe.

Ich erklär euch mein Problem auf eine andere Weise: Wenn ich ein Image in VB einfüge und dieses dann bewege, dann blinkt es die ganze Zeit, da das Bild dauernd refresht werden muss. Füge ich es als ein Bild in einer Picturebox einfüge, dann blinkt das Ganze nicht, habe aber keinen transparenten Hintergrund mehr. Und das ist das Wichtige: Ein transparenter Hintergrund.

Ich denke, ich habs halbwegs verständlich erklärt.


JC schrieb am 25.10.2002 um 14:42

Ah, du benötigst eine transparente PictureBox?

Hier ist ein Freeware-Control, die Vemod SeeThroughPictureBox

Edit: Ach ja, die URL: http://www.vb-components.com/


Hiob schrieb am 25.10.2002 um 14:55

Danke !!


JC schrieb am 25.10.2002 um 14:59

Darf ich dich abschließend - nach Aufklärung des Missverständnisses - noch darauf aufmerksam machen?

Ich denke, somit können sich in Zukunft solche Situationen vermeiden lassen. :)

Danke.


Hiob schrieb am 25.10.2002 um 16:20

Danke für den Tipp JC. Ich merks mir jetzt.

Das Proggi ist ja fast perfekt, nur hab ich Probleme mit dem Aufruf. Die LoadPicture Funktion wurde ja ganz leicht verändert, aber ich finde keine Hilfe, FAQs o.ä. die mir genau sagen, was ich nun anders machen soll. Kennst du einen guten Hilfelink?

mfg Hiob




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2026