Page 1 of 1

How to combine two images

Posted: Thursday 21st March 2024 9:48am
by bill-lancaster
I have two images, square.png and circle.png, both the same size and are black & white.
How can I merge them so that that are both shown in a new image?

Re: How to combine two images

Posted: Thursday 21st March 2024 11:48am
by BruceSteers
please describe "merge"

should they be next to each other or one on top of the other.

do they have transparent backgrounds?

Can you not just use Paint.classs to paint one image on the other?


Paint.Begin(hSquarePic)
Paint.DrawPicture(hRoundPic, 0, 0, Paint.W, Paint.H)
Paint.End


Re: How to combine two images

Posted: Thursday 21st March 2024 11:58am
by bill-lancaster
This does it!
For x = 0 To hImageSquare.W - 1
For y = 0 To hImageSquare.H - 1
If hImageSquare[x, y] <> -16777216 Then hImageNew[x, y] = hImageSquare[x, y]
If hImageCircle[x, y] <> -16777216 Then hImageNew[x, y] = hImageCircle[x, y]
Next
Next

The value 16777216 is the colour of the background. 16777215 = White

Re: How to combine two images

Posted: Thursday 21st March 2024 12:20pm
by bill-lancaster
Thanks Bruce, by 'merge' I mean the overlaying one image over the other.

Re: How to combine two images

Posted: Thursday 21st March 2024 1:13pm
by BruceSteers
Whatever works for you dude.

does it have to be an image that you read/overlay?
you could just draw it


Dim p As Picture = New Picture(300, 300)
p.Image.Fill(Color.White) ' fill white background

Paint.Begin(p)

'  draw a blue square with 10 px margin
Paint.FillRect(10, 10, 280, 280, Color.blue)

' draw a green circle, centered and radius 10px less than image size
Paint.Background = Color.green
Paint.Arc(150, 150, 140)
Paint.Fill()
Paint.End

Re: How to combine two images

Posted: Thursday 21st March 2024 1:19pm
by bill-lancaster
and Paint.DrawImage(hImageCircle, 0, 0, 112, 112)
works just fine.
Thanks again