Re: copy image to windows clipboard?



Hello,

Your assumption about lacks in the Img BMP parser are correct.
I've implemented the missing 16 and 32 bit format parser (for reading only)
and put a new binary version of Img
onto my homepage: http://www.posoft.de/download/tkimg/Img1.3.zip
There is also a little test program (based on your code published here) on
the Tclers Wiki: http://wiki.tcl.tk/15647

If I get positive feedback (hopefully) the changes will make it into the Img
sources on SourceForge.

Paul

P.S.: The 16 and 32 bit based BMP format is typically not used with image
files. Windows uses it, when copying images into the clipboard. So, you
should try to test with 16 and 32 bit display settings.


<palmtcl@xxxxxxxxx> schrieb im Newsbeitrag
news:1142361311.282086.180470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Well it turns out that the offset (14/66 etc) depends on the bitmap.
Here's a new and improved version of write_bitmap_header that seems to
work much better. I had thought the file header field that contained
the offset to the bitmap was the offset to the bitmap header. It is
actually the offset to the pixel values so we need to skip over the
color table entries etc.
GIMP, XP Picture viewer and Paint all show it correctly. Img still
complains about unsupported RLE format. I'm not sure if that's because
of lingering bugs in this function or it really is a Img unsupported
(but valid) format. Anyways, here's the proc:

proc write_bmp_file {filename bmp} {
# Assumes $bmp is clipboard content in format 8 (CF_DIB)

# First parse the bitmap data to collect header information
binary scan $bmp "iiissiiiiii" size width height planes bitcount
compression sizeimage xpelspermeter ypelspermeter clrused clrimportant

# We only handle BITMAPINFOHEADER right now (size must be 40)
if {$size != 40} {
error "Unsupported bitmap format. Header size=$size"
}

# We need to figure out the offset to the actual bitmap data
# from the start of the file header. For this we need to know the
# size of the color table which directly follows the
BITMAPINFOHEADER
if {$bitcount == 0} {
error "Unsupported format: implicit JPEG or PNG"
} elseif {$bitcount == 1} {
set color_table_size 2
} elseif {$bitcount == 4} {
# TBD - Not sure if this is the size or the max size
set color_table_size 16
} elseif {$bitcount == 8} {
# TBD - Not sure if this is the size or the max size
set color_table_size 256
} elseif {$bitcount == 16 || $bitcount == 32} {
if {$compression == 0} {
# BI_RGB
set color_table_size $clrused
} elseif {$compression == 3} {
# BI_BITFIELDS
set color_table_size 3
} else {
error "Unsupported compression type '$compression' for
bitcount value $bitcount"
}
} elseif {$bitcount == 24} {
set color_table_size $clrused
} else {
error "Unsupported value '$bitcount' in bitmap bitcount field"
}

set filehdr_size 14; # sizeof(BITMAPFILEHEADER)
set bitmap_file_offset [expr
{$filehdr_size+$size+($color_table_size*4)}]
set filehdr [binary format "a2 i x2 x2 i" "BM" [expr {$filehdr_size
+ [string length $bmp]}] $bitmap_file_offset]

set fd [open $filename w]
fconfigure $fd -translation binary

puts -nonewline $fd $filehdr
puts -nonewline $fd $bmp

close $fd
}



.



Relevant Pages

  • Re: BMP
    ... That's definitely not a bmp header. ... about a bitmap after it's loaded. ...  4 | data offset ...
    (comp.graphics.algorithms)
  • Re: BMP pixel array
    ... Is this a .BMP file or a Bitmap data array? ... is it using some kind of compression such as RLE or Bit-fields or is the data uncompressed? ... > files with an Info Header of 40 byte. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Storing/Saving a BMP in ASM
    ... To save a BMP in any language, assuming you have access to the pixel's ... values on screen (you can read the bitmap from screen), ... Info on how to store the lines and what the header should ...
    (comp.lang.asm.x86)
  • Re: Binary reading of image data
    ... I thought that reading the binary image would produce a vector ... It is not an SGI file format. ... and just worked with the bitmap. ... also had use a hex editor to remove the 54 byte header from the ...
    (comp.graphics.apps.gnuplot)
  • Re: Cannot Save to my desktop
    ... click on a picture I want to save and choose .bmp ... unreadable format. ... could do this and get a bitmap file that I could open ... Internet Explorer Save As BMP Problem ...
    (microsoft.public.windowsxp.photos)