[Win32utils-devel] Getting image size for win32-clipboard
Heesob Park
phasis at gmail.com
Sat Apr 18 10:20:10 EDT 2009
2009/4/18 Daniel Berger <djberg96 at gmail.com>:
> On Sat, Apr 18, 2009 at 3:19 AM, Heesob Park <phasis at gmail.com> wrote:
>
> Thanks Heesob, that worked. There are a couple of things I still don't
> understand, though. I used the same code as before:
>
> File.open('clippy.bmp', 'wb'){ |fh|
> fh.write Clipboard.data(Clipboard::DIB)
> }
>
> The resulting file is larger than the original file in my experiments
> by a few bytes. Why? I can't visually detect any differences in the
> image, but I thought it was curious.
>
I guess the difference is just a dummy data for the data alignment.
> Also, it seems like we ought to be able to remove the memcpy near the
> end, since 'buf' is reassigned anyway. But, if I remove it, I get an
> "out of memory" error if I attempt to open the file.
>
I'm not sure why you want to remove it. it is an essential part.
> Last, if I replace Clipboard::DIB with Clipboard::ENHMETAFILE I get a segfault.
>
ENHMETAFILE is nothing to do with DIB or BITMAT.
it must be handled differently.
After insert GetEnhMetaFileBits API to window-pr/lib/windows/gdi/bitmat.rb
API.new('GetEnhMetaFileBits', 'LLP', 'L', 'gdi32')
Test with
File.open('aaa.wmf','wb') { |f|
f.write(Clipboard.data(Clipboard::ENHMETAFILE)) }
Here is a patch for ENHMETAFILE
--- clipboard.rb 2009-04-18 23:11:05.000000000 +0900
+++ clipboard.rb.new 2009-04-18 23:08:38.000000000 +0900
@@ -3,6 +3,7 @@
require 'windows/error'
require 'windows/shell'
require 'windows/msvcrt/buffer'
+require 'windows/gdi/bitmap'
# The Win32 module serves as a namespace only.
module Win32
@@ -18,12 +19,14 @@
include Windows::Error
include Windows::Shell
include Windows::MSVCRT::Buffer
+ include Windows::GDI::Bitmap
extend Windows::Clipboard
extend Windows::Memory
extend Windows::Error
extend Windows::Shell
extend Windows::MSVCRT::Buffer
+ extend Windows::GDI::Bitmap
# The version of this library
VERSION = '0.5.0'
@@ -93,8 +96,10 @@
clip_data.strip!
when HDROP
clip_data = get_file_list(handle)
- when DIB, BITMAP, ENHMETAFILE
+ when DIB, BITMAP
clip_data = get_image_data(handle)
+ when ENHMETAFILE
+ clip_data = get_meta_data(handle)
else
raise Error, 'format not supported'
end
@@ -281,6 +286,14 @@
buf
end
+ def self.get_meta_data(handle)
+ buf = nil
+ buf_size = GetEnhMetaFileBits(handle,0,nil)
+ buf = 0.chr * buf_size
+ GetEnhMetaFileBits(handle,buf_size,buf)
+ buf
+ end
+
# Get and return an array of file names that have been copied.
#
def self.get_file_list(handle)
Regards,
Park Heesob
More information about the win32utils-devel
mailing list