May be this help you : https://wiki.tcl-lang.org/page/Copy+image+to+and+from+the+Windows+clipboard.
Saludos,
Alejandro
[email protected] schrieb am Freitag, 7. April 2023 um 01:43:24 UTC+2:
May be this help you : https://wiki.tcl-lang.org/page/Copy+image+to+and+from+the+Windows+clipboard.
Saludos,
Alejandro
Thanks, but the example seems to do the same thing as I did until now: The procedure Img2Clipboard puts BMP format into the clipboard, not PNG.
Am 06.04.2023 um 23:47 schrieb Alexandru:
I would like to:
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this ::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end] ::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanksIn BMP, you don't have an alpha channel, but you have a transparent
Alexandru
color (like in gif). If this is ok for you, use it.
It is quite uncommon to paste png via Windows clipbord. The BMP& friends
is used. There might be alpha channels there to.
Take care,
Harald
I would like to:
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
Am 07.04.23 um 02:05 schrieb Alexandru:Yes, I realize this too.
[email protected] schrieb am Freitag, 7. April 2023 um 01:43:24 UTC+2:
May be this help you : https://wiki.tcl-lang.org/page/Copy+image+to+and+from+the+Windows+clipboard.
Saludos,
Alejandro
Thanks, but the example seems to do the same thing as I did until now: The procedure Img2Clipboard puts BMP format into the clipboard, not PNG.The bottom example handles PNG, but it is the otehr way round (get PNG
from clipboard)
Christian
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2:
Am 06.04.2023 um 23:47 schrieb Alexandru:
I would like to:In BMP, you don't have an alpha channel, but you have a transparent
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
color (like in gif). If this is ok for you, use it.
It is quite uncommon to paste png via Windows clipbord. The BMP& friends
is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?
Am 07.04.2023 um 11:43 schrieb Alexandru:Here are both procedures, one that creates an image, one that puts it into the clipboard as BMP and also saves it to an PNG file.
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2:
Am 06.04.2023 um 23:47 schrieb Alexandru:
I would like to:In BMP, you don't have an alpha channel, but you have a transparent
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
color (like in gif). If this is ok for you, use it.
It is quite uncommon to paste png via Windows clipbord. The BMP& friends >> is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?The bmp header has the color index of the transparent color.
That should just work
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 12:00:30 UTC+2:
Am 07.04.2023 um 11:43 schrieb Alexandru:Here are both procedures, one that creates an image, one that puts it into the clipboard as BMP and also saves it to an PNG file.
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2:The bmp header has the color index of the transparent color.
Am 06.04.2023 um 23:47 schrieb Alexandru:
I would like to:In BMP, you don't have an alpha channel, but you have a transparent
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
color (like in gif). If this is ok for you, use it.
It is quite uncommon to paste png via Windows clipbord. The BMP& friends >>>> is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?
That should just work
The PNG file is transparent, the BMP in the clipboard is not.
proc Image2Clipboard {imgname} {
::twapi::open_clipboard
::twapi::empty_clipboard
ImageColorSetTransparent $imgname
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
}
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
$img write temp.png -format "png -alpha 0.0"
}
Am 07.04.2023 um 12:44 schrieb Alexandru:
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 12:00:30 UTC+2:
Am 07.04.2023 um 11:43 schrieb Alexandru:Here are both procedures, one that creates an image, one that puts it into the clipboard as BMP and also saves it to an PNG file.
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2: >>>> Am 06.04.2023 um 23:47 schrieb Alexandru:The bmp header has the color index of the transparent color.
I would like to:In BMP, you don't have an alpha channel, but you have a transparent >>>> color (like in gif). If this is ok for you, use it.
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
It is quite uncommon to paste png via Windows clipbord. The BMP& friends
is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?
That should just work
The PNG file is transparent, the BMP in the clipboard is not.
proc Image2Clipboard {imgname} {
::twapi::open_clipboard
::twapi::empty_clipboard
ImageColorSetTransparent $imgname
# First 14 bytes are bitmapfileheader - get rid of this ::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end] ::twapi::close_clipboard
}
proc ImageColorSetTransparent {img {color #ffffff}} {The following script copies and pastes images with alpha channel.
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
$img write temp.png -format "png -alpha 0.0"
}
The reference PNG image with alpha channel can be downloaded here: https://www.tcl3d.org/bawt/download/Preview/vegetation.png
set useImg false
set f "vegetation.png"
package require twapi
package require Tk
puts -nonewline "Using Tcl [info patch], Tk [package version Tk]"
if { $useImg } {
package require Img
puts -nonewline ", Img [package version Img]"
}
puts ""
set CF_PNG 49460
proc Clipboard2Img {} {
twapi::open_clipboard
# Assume clipboard content is in format CF_PNG
set retVal [catch {twapi::read_clipboard $::CF_PNG} clipData]
if { $retVal != 0 } {
error "Invalid or no content in clipboard"
}
set phImg [image create photo]
$phImg put $clipData -format png
twapi::close_clipboard
return $phImg
}
proc Img2Clipboard { phImg } {
twapi::open_clipboard
twapi::empty_clipboard
set retVal [catch {package present Img} versionStr]
if { $retVal == 0 } {
twapi::write_clipboard $::CF_PNG [binary decode base64 [$phImg data -format png]]
} else {
twapi::write_clipboard $::CF_PNG [$phImg data -format png]
}
twapi::close_clipboard
}
label .l1 -background yellow
label .l2 -background lightgreen
pack .l1 .l2
puts "Load file $f"
set ph1 [image create photo -file $f -format "png"]
puts "Put image into clipboard"
Img2Clipboard $ph1
.l1 configure -image $ph1
update
puts "Get image from clipboard"
set ph2 [Clipboard2Img]
.l2 configure -image $ph2
update
bind . <Escape> exit
Paul Obermeier schrieb am Samstag, 8. April 2023 um 22:43:27 UTC+2:into PowerPoint and nothing happens. It's like the clipboard were empty, which is not.
Am 07.04.2023 um 12:44 schrieb Alexandru:
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 12:00:30 UTC+2:The following script copies and pastes images with alpha channel.
Am 07.04.2023 um 11:43 schrieb Alexandru:Here are both procedures, one that creates an image, one that puts it into the clipboard as BMP and also saves it to an PNG file.
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2: >>>>>> Am 06.04.2023 um 23:47 schrieb Alexandru:The bmp header has the color index of the transparent color.
I would like to:In BMP, you don't have an alpha channel, but you have a transparent >>>>>> color (like in gif). If this is ok for you, use it.
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones,
3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
It is quite uncommon to paste png via Windows clipbord. The BMP& friends >>>>>> is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?
That should just work
The PNG file is transparent, the BMP in the clipboard is not.
proc Image2Clipboard {imgname} {
::twapi::open_clipboard
::twapi::empty_clipboard
ImageColorSetTransparent $imgname
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
}
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
$img write temp.png -format "png -alpha 0.0"
}
The reference PNG image with alpha channel can be downloaded here: https://www.tcl3d.org/bawt/download/Preview/vegetation.png
set useImg false
set f "vegetation.png"
package require twapi
package require Tk
puts -nonewline "Using Tcl [info patch], Tk [package version Tk]"
if { $useImg } {
package require Img
puts -nonewline ", Img [package version Img]"
}
puts ""
set CF_PNG 49460
proc Clipboard2Img {} {
twapi::open_clipboard
# Assume clipboard content is in format CF_PNG
set retVal [catch {twapi::read_clipboard $::CF_PNG} clipData]
if { $retVal != 0 } {
error "Invalid or no content in clipboard"
}
set phImg [image create photo]
$phImg put $clipData -format png
twapi::close_clipboard
return $phImg
}
proc Img2Clipboard { phImg } {
twapi::open_clipboard
twapi::empty_clipboard
set retVal [catch {package present Img} versionStr]
if { $retVal == 0 } {
twapi::write_clipboard $::CF_PNG [binary decode base64 [$phImg data -format png]]
} else {
twapi::write_clipboard $::CF_PNG [$phImg data -format png]
}
twapi::close_clipboard
}
label .l1 -background yellow
label .l2 -background lightgreen
pack .l1 .l2
puts "Load file $f"
set ph1 [image create photo -file $f -format "png"]
puts "Put image into clipboard"
Img2Clipboard $ph1
.l1 configure -image $ph1
update
puts "Get image from clipboard"
set ph2 [Clipboard2Img]
.l2 configure -image $ph2
update
bind . <Escape> exit
Hi Paul,
Many thanks, your code is a step forward but though it works inside Tcl environment, it does not work with Windows. It's like the format in the clipboard is not understandable for Windows. After puting the image into the clipboard, I try to paste it
Am 11.04.2023 um 16:39 schrieb Alexandru:into PowerPoint and nothing happens. It's like the clipboard were empty, which is not.
Paul Obermeier schrieb am Samstag, 8. April 2023 um 22:43:27 UTC+2:
Am 07.04.2023 um 12:44 schrieb Alexandru:
Harald Oehlmann schrieb am Freitag, 7. April 2023 um 12:00:30 UTC+2: >>>> Am 07.04.2023 um 11:43 schrieb Alexandru:The following script copies and pastes images with alpha channel.
Here are both procedures, one that creates an image, one that puts it into the clipboard as BMP and also saves it to an PNG file.Harald Oehlmann schrieb am Freitag, 7. April 2023 um 11:39:06 UTC+2: >>>>>> Am 06.04.2023 um 23:47 schrieb Alexandru:The bmp header has the color index of the transparent color.
I would like to:In BMP, you don't have an alpha channel, but you have a transparent >>>>>> color (like in gif). If this is ok for you, use it.
1. copy the content of an window into an image,
2. replace the white pixels in the image with transparent ones, >>>>>>> 3. place the image into the Windows clipboard
The issue is at point 3.
Currently I can realize point 3 only with bitmap format:
::twapi::open_clipboard
::twapi::empty_clipboard
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
But bitmaps does not support transparent pixels, right?
So I guess I must use PNG format.
But how can I place PNG format into the clipboard?
Many thanks
Alexandru
It is quite uncommon to paste png via Windows clipbord. The BMP& friends
is used. There might be alpha channels there to.
Take care,
Harald
Thanks. How can I define tranparent color?
Currently my procedure does this:
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
}
How can I adapt it to make BMP transparent?
That should just work
The PNG file is transparent, the BMP in the clipboard is not.
proc Image2Clipboard {imgname} {
::twapi::open_clipboard
::twapi::empty_clipboard
ImageColorSetTransparent $imgname
# First 14 bytes are bitmapfileheader - get rid of this
::twapi::write_clipboard 8 [string range\
[binary decode base64 [$imgname data -format bmp]] 14 end]
::twapi::close_clipboard
}
proc ImageColorSetTransparent {img {color #ffffff}} {
set y 0
foreach row [$img data] {
set x 0
foreach pixel $row {
if {$color==$pixel} {
$img transparency set $x $y 1
}
incr x
}
incr y
}
$img write temp.png -format "png -alpha 0.0"
}
The reference PNG image with alpha channel can be downloaded here: https://www.tcl3d.org/bawt/download/Preview/vegetation.png
set useImg false
set f "vegetation.png"
package require twapi
package require Tk
puts -nonewline "Using Tcl [info patch], Tk [package version Tk]"
if { $useImg } {
package require Img
puts -nonewline ", Img [package version Img]"
}
puts ""
set CF_PNG 49460
proc Clipboard2Img {} {
twapi::open_clipboard
# Assume clipboard content is in format CF_PNG
set retVal [catch {twapi::read_clipboard $::CF_PNG} clipData]
if { $retVal != 0 } {
error "Invalid or no content in clipboard"
}
set phImg [image create photo]
$phImg put $clipData -format png
twapi::close_clipboard
return $phImg
}
proc Img2Clipboard { phImg } {
twapi::open_clipboard
twapi::empty_clipboard
set retVal [catch {package present Img} versionStr]
if { $retVal == 0 } {
twapi::write_clipboard $::CF_PNG [binary decode base64 [$phImg data -format png]]
} else {
twapi::write_clipboard $::CF_PNG [$phImg data -format png]
}
twapi::close_clipboard
}
label .l1 -background yellow
label .l2 -background lightgreen
pack .l1 .l2
puts "Load file $f"
set ph1 [image create photo -file $f -format "png"]
puts "Put image into clipboard"
Img2Clipboard $ph1
.l1 configure -image $ph1
update
puts "Get image from clipboard"
set ph2 [Clipboard2Img]
.l2 configure -image $ph2
update
bind . <Escape> exit
Hi Paul,
Many thanks, your code is a step forward but though it works inside Tcl environment, it does not work with Windows. It's like the format in the clipboard is not understandable for Windows. After puting the image into the clipboard, I try to paste it
I played around with different format numbers and left the wrong one in the script.
The PNG format number is:
set CF_PNG 49494
Paul
Hi Alexandru,
It seems that the Windows clipboard has a long story of problems with transparency support .
I guess a practical approach for you could be use a program to view the clipboard's content such as InsideClipboard of www.nirsoft.net.
For example, if i copy a PNG file from MSPaint , InsideClipboard show me this :
3 CF_METAFILEPICT Metafile 0 3
8 CF_DIB Memory 20.480 4
49163 Embed Source Storage 0 1
49166 Object Descriptor Memory 174 2
( the columns are Format ID, Format Name, Handle Type, Size and Index respectively)
In other hand other program, Free Clipboard Viewer, show more formats, previews, etc but not the format code.
Saludos,
Alejandro
I played around with different format numbers and left the wrong one in
the script.
The PNG format number is:
set CF_PNG 49494
Paul
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 158:14:40 |
| Calls: | 12,094 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,755 |