Page 1 of 1
Paste Image
Posted: Mon Sep 24, 2012 11:12 pm
by spacebuddy
Is there any way to paste an image into another image in PB?
I know grabImage creates a new image, but I need to paste several small images
into a big image. I could not find any call to do this in the help file.
Thanks.
Re: Paste Image
Posted: Tue Sep 25, 2012 3:23 am
by TI-994A
spacebuddy wrote:...I need to paste several small images into a big image.
Hi spacebuddy! I believe that the DrawImage() function is what you're looking for. Here's an example:
Code: Select all
EnableExplicit
UseJPEGImageDecoder()
UsePNGImageDecoder()
Enumeration
#MainWindow
#ImageDisplay
#image1
#image2
EndEnumeration
Define wFlags.i, imageFile.s
imageFile = OpenFileRequester("Select Main Image:", "", "JPG|*.jpg|BMP|*.bmp|PNG|*.png", 0)
If imageFile And LoadImage(#image1, imageFile)
imageFile = ""
imageFile = OpenFileRequester("Select Smaller Image:", "", "JPG|*.jpg|BMP|*.bmp|PNG|*.png", 0)
If imageFile And LoadImage(#image2, imageFile)
wFlags = #PB_Window_SizeGadget | #PB_Window_ScreenCentered
wFlags = wFlags | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "DrawImage", wFlags)
ImageGadget(#ImageDisplay, 0, 0, 640, 480, 0)
If StartDrawing(ImageOutput(#image1))
DrawImage(ImageID(#image2), 30, 30, ImageWidth(#image2), ImageHeight(#image2))
StopDrawing()
EndIf
SetGadgetState(#ImageDisplay, ImageID(#image1))
Else
End
EndIf
Else
End
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Hope it helps!
Re: Paste Image
Posted: Tue Sep 25, 2012 4:22 pm
by spacebuddy
yes, that works thanks.
When I save the image as a .png it is not transparent.
How do you make it transparent?
Re: Paste Image
Posted: Tue Sep 25, 2012 4:57 pm
by wilbert
spacebuddy wrote:How do you make it transparent?
Was the image you draw onto created transparent ?
Like
Code: Select all
CreateImage(0, 255, 255, 32 | #PB_Image_Transparent)
Re: Paste Image
Posted: Tue Sep 25, 2012 5:19 pm
by TI-994A
spacebuddy wrote:When I save the image as a .png it is not transparent.
Hello again spacebuddy. If your original image already has transparency, saving it using the UsePNGImageEncoder() will preserve the transparency, even if you use DrawImage() to place another non-transparent image onto it. I've modified the example to save the resultant image as a PNG file:
Code: Select all
EnableExplicit
UseJPEGImageDecoder()
UsePNGImageDecoder()
UsePNGImageEncoder()
Enumeration
#MainWindow
#ImageDisplay
#image1
#image2
EndEnumeration
Define wFlags.i, imageFile.s
imageFile = OpenFileRequester("Select Main Image:", "", "JPG|*.jpg|BMP|*.bmp|PNG|*.png", 0)
If imageFile And LoadImage(#image1, imageFile)
imageFile = ""
imageFile = OpenFileRequester("Select Smaller Image:", "", "JPG|*.jpg|BMP|*.bmp|PNG|*.png", 0)
If imageFile And LoadImage(#image2, imageFile)
wFlags = #PB_Window_SizeGadget | #PB_Window_ScreenCentered
wFlags = wFlags | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "DrawImage", wFlags)
ImageGadget(#ImageDisplay, 0, 0, 640, 480, 0)
If StartDrawing(ImageOutput(#image1))
DrawImage(ImageID(#image2), 30, 30, ImageWidth(#image2), ImageHeight(#image2))
StopDrawing()
EndIf
SetGadgetState(#ImageDisplay, ImageID(#image1))
imageFile = SaveFileRequester("Enter/Select Filename:", "C:\savedImage.png", "PNG|*.png", 0)
SaveImage(#image1, imageFile, #PB_ImagePlugin_PNG)
Else
End
EndIf
Else
End
EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
Re: Paste Image
Posted: Tue Sep 25, 2012 5:50 pm
by spacebuddy
Thank you all, got it working
