Save clipboard image

Windows specific forum
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Save clipboard image

Post by cecilcheah »

Hi

This is really frustrating.

Is there a function in v3.7 to save an image in clipboard directly to a file?

I could not find any. I search the forum, but did not really locate any function to do this either. I found a thread with really a lot of scripts, but when i try to use part of the code

viewtopic.php?t=3705&highlight=clipboard+save

Code: Select all

ciHwnd = GetClipboardData_(#CF_BITMAP)
GetObject_(ciHwnd, SizeOf(BITMAP), @bmp)
SelectObject_(hDC, ciHwnd)
IData\width = bmp\bmWidth
IData\height = bmp\bmHeight
IData\bits = bmp\bmBitsPixel*bmp\bmPlanes
pad = (bmp\bmWidthBytes-IData\width)*IData\height
iHwnd = CreateCompatibleBitmap_(hDC, IData\width, IData\height)
it tells me IData Structure is not defined.


This should be a simple thing to do. As i find in another thread, the problem is:
We do not know the size of the image in clipboard to creatImage

Please can anyone help?.

Cecil[/code]
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Code: Select all

Structure ImageData
width.l
height.l
colors.l
chars.l
bits.b
EndStructure
Global IData.ImageData
Read the source code more carefully! :roll:
--Kale

Image
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Code: Select all

ciHwnd = GetClipboardData_(#CF_BITMAP)
If ciHwnd
  GetObject_(ciHwnd, SizeOf(BITMAP), bm.BITMAP)
  CreateImage(0, bm\bmWidth, bm\bmHeight)
  StartDrawing(ImageOutput())
  DrawImage(ciHwnd, 0, 0)
  StopDrawing()
  SaveImage(0, "myimage.bmp", #PB_ImagePlugin_BMP)
EndIf
El_Choni
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Thanks all.

I really should read the source properly. Save your and my time.

And thanks to El_Choni, i will try your code later

Thanks

Cecil
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Hi El_Choni

There seems to be a problem with your code.

My code is as follow:

Code: Select all

keybd_event_(#MOD_SHIFT|#VK_SNAPSHOT,0,0,0) 
OpenClipboard_(ParentHandle) 
        Debug IsClipboardFormatAvailable_(#CF_BITMAP)
        ciHwnd.l = GetClipboardData_(#CF_BITMAP) 
          Debug ciHwnd 
        If ciHwnd 
          GetObject_(ciHwnd, SizeOf(BITMAP), bm.BITMAP) 
          CreateImage(0, bm\bmWidth, bm\bmHeight) 
          StartDrawing(ImageOutput()) 
          DrawImage(ciHwnd, 0, 0) 
          StopDrawing() 
Both Debug shows that :
1. Clipboard format BITMAP is not available
2. ciHwnd is NULL

I know the image is captured because i can paste it into PaintShopPro,
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Hi there

IT is ok now. I have solved the problem.

Thanks

Cecil
Cor
Enthusiast
Enthusiast
Posts: 124
Joined: Fri Apr 25, 2003 7:52 pm
Location: Netherlands
Contact:

Post by Cor »

Please let us know what the problem was so we all can benefit from it :wink:
Cor de Visser

Registered PureBasic user

Author of ChordPlanet
Made with PureBasic
http://www.chordplanet.com
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Hi

it seems that adding the following line will solve the problem:

Code: Select all

Delay(1)
So the entire code:

Code: Select all

keybd_event_(#MOD_SHIFT|#VK_SNAPSHOT,1,0,0) 
Delay(1) 
            OpenClipboard_(#NULL) 
            Debug IsClipboardFormatAvailable_(#CF_BITMAP)
            ciHwnd.l = GetClipboardData_(#CF_BITMAP) 
            Debug ciHwnd 
            If ciHwnd 
              GetObject_(ciHwnd, SizeOf(BITMAP), bm.BITMAP) 
              CreateImage(0, bm\bmWidth, bm\bmHeight) 
              StartDrawing(ImageOutput()) 
              DrawImage(ciHwnd, 0, 0) 
              StopDrawing() 
              Select bmpjpg 
              Case 0
                SaveImage(0, FileName$, #PB_ImagePlugin_BMP)
              Case 1
                SaveImage(0, FileName$, #PB_ImagePlugin_JPEG)
              EndSelect
Cecil
Post Reply