Page 1 of 1
					
				Add text to image
				Posted: Thu Jun 05, 2003 9:58 am
				by cecilcheah
				Hi there
One more question today.
If a desktop image is captured in a clipboard, how do i add some text to it? For example i want to put some text in the center of the image, how do i do this?
Thanks
Cecil
			 
			
					
				
				Posted: Thu Jun 05, 2003 10:19 am
				by Saboteur
				Look for 2D Drawing in help, there is an example. With StartDrawing() function and ImageOutput(), WindowOutput(), etc... you can draw where you want.  

 
			 
			
					
				
				Posted: Thu Jun 05, 2003 11:07 pm
				by cecilcheah
				You are right. It has an example to show you how to draw text over an image in a window/gadget, but not in a clipboard .
How can i add some text to a captured image when the image is in the clipboard? I try with ImageOutput but it always give me an error.
Thanks
Cecil
			 
			
					
				
				Posted: Thu Jun 05, 2003 11:24 pm
				by Kale
				I imagine at some time you wish to save the captured screen image to disk? why not add the text in the save function, e.g. write the image to disk then draw on it, all in one go?
			 
			
					
				
				Posted: Fri Jun 06, 2003 12:05 am
				by tinman
				Code: Select all
If CreateImage(0, 320, 200)
  foo.l = GetClipboardData(#PB_Clipboard_Image)
  If foo
    If StartDrawing(ImageOutput())
      DrawImage(foo, 0, 0)
      DrawText("some crap")
      StopDrawing()
    EndIf
    SaveImage(0, "c:\blah.bmp")
  EndIf
EndIf
End
Edit: cleaned up, forgot code tags.
 
			 
			
					
				
				Posted: Fri Jun 06, 2003 12:07 am
				by El_Choni
				Try this (providing you already have an image in the clipboard and you know its width and height):
Code: Select all
MyImage = CreateImage(0, width, height)
ImageID = GetClipboardData(#PB_ClipboardImage)
StartDrawing(ImageOutput())
DrawImage(ImageID, 0, 0)
; your own drawing here
StopDrawing()
SetClipboardData(#PB_ClipboardImage, UseImage(0))
 
			 
			
					
				
				Posted: Fri Jun 06, 2003 7:16 am
				by cecilcheah
				Thanks
I see where my error is.
Question:
Your code
Code: Select all
ImageID = GetClipboardData(#PB_ClipboardImage) 
StartDrawing(ImageOutput()) 
I try with this:
image=pasteImage ' pasteImage is a procedere inside my programme like your GetClipboardData(#PB_ClipboardImage) 
StartDrawing(ImageOutput()) 
Do i have to use ImageID instead of image to let PB register a new ID for the image? I was always getting a GPF yesterday doing this way.
Always i have a question:
Code: Select all
MyImage = CreateImage(0, width, height) 
ImageID = GetClipboardData(#PB_ClipboardImage) 
What is MyImage for? Is it the same as ImageID. I think this is where i have a problem in understanding PB. Can i use:
MyImage = CreateImage(0, width, height) 
MyImage = GetClipboardData(#PB_ClipboardImage) 
instead?
I will try your way later.
How long does it take you to be so good in PB and API?
Cecil
 
			 
			
					
				
				Posted: Fri Jun 06, 2003 2:11 pm
				by tinman
				cecilcheah wrote:I try with this:
image=pasteImage ' pasteImage is a procedere inside my programme like 
pasteImage the way you have written it here is not a procedure. Procedures have brackets after them. pasteImage in this case will be a variable which (probably) has a value of zero, which is why your code GPFs.
Do i have to use ImageID instead of image to let PB register a new ID for 
No, the value returned by GetClipboardData is just a handle to the data, so you can get access to it later. You can give it any variable name you want.
Code: Select all
MyImage = CreateImage(0, width, height) 
ImageID = GetClipboardData(#PB_ClipboardImage) 
What is MyImage for? Is it the same as ImageID. I think this is where i 
 
MyImage is just a handle to the image that is created. It has the same purpose as ImageID, but it is different (MyImage refers to the image created by CreateImage and ImageID refers to the image from the clipboard).
MyImage = CreateImage(0, width, height) 
MyImage = GetClipboardData(#PB_ClipboardImage) 
You can do that, but then MyImage will refer to the image from the clipbaord. You can still access the image you create in other ways, so it does not matter that you change the value like this. But it is quite needless to do so.
 
			 
			
					
				
				Posted: Fri Jun 06, 2003 2:14 pm
				by El_Choni
				Hi. MyImage and ImageID are both Bitmap handles:
Code: Select all
MyImage = CreateImage(0, width, height) ; create a new empty bitmap, retrieve handle
ImageID = GetClipboardData(#PB_ClipboardImage) ; get clipboard bitmap handle
StartDrawing(ImageOutput()) ; start drawing to the bitmap we created
DrawImage(ImageID, 0, 0) ; draw the image from clipboard
; your own drawing here 
StopDrawing() 
SetClipboardData(#PB_ClipboardImage, MyImage) ; we can use UseImage(0) instead, it's the same