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.
Paste Image
Re: Paste Image
Hi spacebuddy! I believe that the DrawImage() function is what you're looking for. Here's an example:spacebuddy wrote:...I need to paste several small images into a big image.
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 : WendTexas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
-
spacebuddy
- Enthusiast

- Posts: 364
- Joined: Thu Jul 02, 2009 5:42 am
Re: Paste Image
yes, that works thanks.
When I save the image as a .png it is not transparent.
How do you make it transparent?
When I save the image as a .png it is not transparent.
How do you make it transparent?
Re: Paste Image
Was the image you draw onto created transparent ?spacebuddy wrote:How do you make it transparent?
Like
Code: Select all
CreateImage(0, 255, 255, 32 | #PB_Image_Transparent)Re: Paste Image
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:spacebuddy wrote:When I save the image as a .png it is not transparent.
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 : WendTexas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
-
spacebuddy
- Enthusiast

- Posts: 364
- Joined: Thu Jul 02, 2009 5:42 am
Re: Paste Image
Thank you all, got it working 

