2 Grafiken übereinander legen

Yoah

Erfahrenes Mitglied
Moin,

ich beschäftige mich gerade ein bisschen mit PictureBoxen und bin an einem Punkt,
wo ich mal wieder Unterstützung und Hilfe benötige!

Ich möchte gerne mal 2 Grafiken übereinander legen und dann als eine Grafik abspeichern.

Hat vielleicht jemand einen Ansatz für mich, oder evtl. schon mehr?

Danke im voraus
 
Hi,

leider kann ich damit nichts anfangen.
Ich suche etwas, das zwei Bilder lädt, sie übereinander legt, und dann abspeichert.
So eine Art Wasserzeichen.
 
Hmpf,

genau das macht es mit ein paar Modifikationen. A bisserle nachdenken hätte Dich sicherlich auf folgende Lösung geführt:

Eine Form mit 3 Pictureboxen (Picture1, Picture2, Picture2). ScaleMode=Pixel; AutoRedraw=True

Einen Commandbutton (Command1)

Code:
Option Explicit

Private Type BlendFunction
    BlendOp                                 As Byte
    BlendFlags                              As Byte
    SourceConstantAlpha                     As Byte
    AlphaFormat                             As Byte
End Type

Private Declare Function AlphaBlend Lib "msimg32.dll" ( _
    ByVal hdcDest As Long, _
    ByVal nXOriginDest As Long, _
    ByVal nYOriginDest As Long, _
    ByVal nWidthDest As Long, _
    ByVal nHeightDest As Long, _
    ByVal hdcSrc As Long, _
    ByVal nXOriginSrc As Long, _
    ByVal nYOriginSrc As Long, _
    ByVal nWidthSrc As Long, _
    ByVal nHeightSrc As Long, _
    ByVal BlendFunction As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
    ByRef Destination As Any, _
    ByRef Source As Any, _
    ByVal Length As Long)

Rem =================================================
Rem == Einblenden des gewünschten Bildes.          ==
Rem =================================================
'
Private Sub BlendPicture(ByVal cControl As PictureBox, _
                         ByVal bBlendFactor As Byte)
    Dim bfBlend                 As BlendFunction
    Dim lBlend                  As Long

    Rem =============================================
    Rem == Einblendevorgang beginnen.              ==
    Rem =============================================
    bfBlend.SourceConstantAlpha = bBlendFactor
    Call CopyMemory(lBlend, bfBlend, 4&)
    Call AlphaBlend(cControl.hDC, 0, 0, cControl.ScaleWidth, _
                    cControl.ScaleHeight, _
                    Picture2.hDC, 0, 0, Picture2.ScaleWidth, _
                    Picture2.ScaleHeight, lBlend)
End Sub

Rem =================================================
Rem == Bilder laden, die überlagert werden sollen. ==
Rem =================================================
'
Private Sub Load_Picture(ByVal cControl As PictureBox, _
                         ByVal szFileName As String)
    Dim pTempPicture            As IPictureDisp

    Set pTempPicture = LoadPicture(szFileName)

    cControl.PaintPicture pTempPicture, 0, 0, _
                cControl.ScaleWidth, cControl.ScaleHeight
    cControl.Picture = cControl.Image
End Sub

Private Sub Command1_Click()
    Call Load_Picture(Picture1, "Bild1")
    Call Load_Picture(Picture2, "Bild2")
    Picture3.Picture = Picture1.Picture
    Call BlendPicture(Picture3, 100)
End Sub


Gruß
Das Orakel
 
Moin,

ich nochmal!

@Orakel, du hast mir echt schon weiter geholfen, jetzt stehe
ich aber vor einem weiteren Problem.
Und zwar ist es im Moment so, dass sich die Bilder an die PictureBox anpassen
und ich hätte es gerne umgekehrt, das sich die Picture Box an die Größe der Bilder anpasst.
Damit ich dann das Picture3 in der Originalgröße (v. Picture1) abspeichern kann.

Kannst du mir nochmal unter die Arme greifen
 
Hi Yoah,

einfach die Autosize Eigenschaft Deiner Picturebox auf True setzen.
Dann mit Picture1.Picture = Loadpicture("Dein Bild") das bild direkt ohne Scalierung laden.

An meinem Beispiel verändert sich nur die Command1_Click Prozedur:
Code:
Private Sub Command1_Click()
    Picture1.Picture = LoadPicture("Bild1.JPG")
    Picture2.Picture = LoadPicture("Bild2.JPG")
    Picture3.Picture = Picture1.Picture
    Call BlendPicture(Picture3, 100)
End Sub

Hope it helps
Das Orakel
 
Zurück