[Win32utils-devel] Getting image size for win32-clipboard

Daniel Berger djberg96 at gmail.com
Fri Apr 17 21:24:30 EDT 2009


On Fri, Apr 17, 2009 at 5:18 PM, Heesob Park <phasis at gmail.com> wrote:
> Hi,
>
> 2009/4/18 Daniel Berger <djberg96 at gmail.com>:
>> Hi,
>>
>> I'm having some trouble getting the image size for win32-clipboard. The
>> basic approach is this:
>>
>>   bmi     = 0.chr * 44 # BITMAPIFO
>>   handle  = GetClipboardData(CF_DIB)
>>   address = GlobalLock(handle)
>>   memcpy(bmi, address, bmi.size)
>>   size_image = bmi[20,4].unpack('L').first # 0 ???
>>
>> This generally seems to work. I copied a small 24-bit color jpg image into
>> my clipboard and can validate that the height and width are correct.
>> However, the size_image always ends up 0.
>>
>> What am I doing wrong? The docs did mention that 24-bit RGB images might
>> return 0. If that's the case, how do I get the size?
>>
> In my test with mspaint.exe, it works fine.
>
> What's your copy process?
> How do I reproduce the bug?

I opened up a small .jpg file with Photoshop Elements 5. I did a
Ctrl-A + Ctrl-C. This was the result:

Header Size: 40
Width: 570
Height: 570
Planes: 1
Bit Count: 24
Compression: 0
Image Size: 0
X Per Meter: 112205
Y Per Meter: 112205
Color Used: 0
Color Import: 0

Ok...this is strange. I opened up the *same* image in Paint, and did a
Ctrl-A + Ctrl-C. This was the result:

Header Size: 40
Width: 570
Height: 570
Planes: 1
Bit Count: 24
Compression: 0
Image Size: 975840
X Per Meter: 112200
Y Per Meter: 112200
Color Used: 0
Color Import: 0

Maybe because it was a jpg instead of a bmp? I'm not sure.

In any case, I've got the initial implementation in CVS. I am having
some trouble actually copying clipboard contents. I tried this:

File.open("test.bmp", "wb"){ |fh| fh.write Clipboard.data(Clipboard::DIB) }

The file size is identical, but I can't open the resulting file - MS
Paint says it doesn't recognize the format.

Please take a look at the code in CVS (and use the latest windows-pr)
and see if everything looks alright.

Thanks,

Dan


More information about the win32utils-devel mailing list