Add text to image
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Add text to image
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
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
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
- tinman
- PureBasic Expert

- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
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
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
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))
El_Choni
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Thanks
I see where my error is.
Question:
Your code
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:
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
I see where my error is.
Question:
Your code
Code: Select all
ImageID = GetClipboardData(#PB_ClipboardImage)
StartDrawing(ImageOutput())
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) 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
- tinman
- PureBasic Expert

- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
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.cecilcheah wrote:I try with this:
image=pasteImage ' pasteImage is a procedere inside my programme like
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.Do i have to use ImageID instead of image to let PB register a new ID for
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).What is MyImage for? Is it the same as ImageID. I think this is where iCode: Select all
MyImage = CreateImage(0, width, height) ImageID = 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.MyImage = CreateImage(0, width, height)
MyImage = GetClipboardData(#PB_ClipboardImage)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
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
El_Choni
