"We are back" « oc.at

Pictures in VB transparent machen

Hiob 25.10.2002 - 13:11 556 8
Posts

Hiob

Addicted
Registered: May 2002
Location: 8010
Posts: 427
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

Guest

Deleted User
Registered: n/a
Location:
Posts: n/a
also ein FORM transparent machen geht nur in VB.NET afaik.

JC

Vereinsmitglied
Disruptor
Avatar
Registered: Feb 2001
Location: Katratzi
Posts: 9066
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

Vereinsmitglied
Disruptor
Avatar
Registered: Feb 2001
Location: Katratzi
Posts: 9066
Das vielleicht bessere Beispiel liefert MS.

Hiob

Addicted
Registered: May 2002
Location: 8010
Posts: 427
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

Vereinsmitglied
Disruptor
Avatar
Registered: Feb 2001
Location: Katratzi
Posts: 9066
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

Addicted
Registered: May 2002
Location: 8010
Posts: 427
Danke !!

JC

Vereinsmitglied
Disruptor
Avatar
Registered: Feb 2001
Location: Katratzi
Posts: 9066
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

Addicted
Registered: May 2002
Location: 8010
Posts: 427
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
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz