Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Beware the new TTY code!


devel / comp.lang.tcl / Put PNG into Windows clipboard

SubjectAuthor
* Put PNG into Windows clipboardAlexandru
+* Re: Put PNG into Windows clipboardlamuzz...@gmail.com
|`* Re: Put PNG into Windows clipboardAlexandru
| `* Re: Put PNG into Windows clipboardChristian Gollwitzer
|  `- Re: Put PNG into Windows clipboardAlexandru
`* Re: Put PNG into Windows clipboardHarald Oehlmann
 `* Re: Put PNG into Windows clipboardAlexandru
  `* Re: Put PNG into Windows clipboardHarald Oehlmann
   `* Re: Put PNG into Windows clipboardAlexandru
    `* Re: Put PNG into Windows clipboardPaul Obermeier
     `* Re: Put PNG into Windows clipboardAlexandru
      `* Re: Put PNG into Windows clipboardPaul Obermeier
       +* Re: Put PNG into Windows clipboardAlexandru
       |`* Re: Put PNG into Windows clipboardlamuzz...@gmail.com
       | `- Re: Put PNG into Windows clipboardAlexandru
       `- Re: Put PNG into Windows clipboardsaitology9

1
Put PNG into Windows clipboard

<cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21679&group=comp.lang.tcl#21679

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:450c:b0:746:b87c:e2f1 with SMTP id t12-20020a05620a450c00b00746b87ce2f1mr2862574qkp.6.1680817645497;
Thu, 06 Apr 2023 14:47:25 -0700 (PDT)
X-Received: by 2002:a05:6214:a4f:b0:56e:952e:23ec with SMTP id
ee15-20020a0562140a4f00b0056e952e23ecmr782581qvb.2.1680817645340; Thu, 06 Apr
2023 14:47:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 6 Apr 2023 14:47:25 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=82.207.255.157; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 82.207.255.157
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
Subject: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Thu, 06 Apr 2023 21:47:25 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1685
 by: Alexandru - Thu, 6 Apr 2023 21:47 UTC

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

Re: Put PNG into Windows clipboard

<942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21680&group=comp.lang.tcl#21680

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:4447:b0:71f:b89c:5ac7 with SMTP id w7-20020a05620a444700b0071fb89c5ac7mr2625696qkp.8.1680824602442;
Thu, 06 Apr 2023 16:43:22 -0700 (PDT)
X-Received: by 2002:ac8:7d14:0:b0:3db:2d18:3f84 with SMTP id
g20-20020ac87d14000000b003db2d183f84mr213624qtb.11.1680824602198; Thu, 06 Apr
2023 16:43:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 6 Apr 2023 16:43:21 -0700 (PDT)
In-Reply-To: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=190.139.63.124; posting-account=Cgy5dQoAAADca6APzXXyHNx6hvwj5mk6
NNTP-Posting-Host: 190.139.63.124
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: lamuzzachiodi@gmail.com (lamuzz...@gmail.com)
Injection-Date: Thu, 06 Apr 2023 23:43:22 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1258
 by: lamuzz...@gmail.com - Thu, 6 Apr 2023 23:43 UTC

May be this help you : https://wiki.tcl-lang.org/page/Copy+image+to+and+from+the+Windows+clipboard.
Saludos,

Alejandro

Re: Put PNG into Windows clipboard

<151c6f96-c93f-4c5d-9998-0ea6143b88cbn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21681&group=comp.lang.tcl#21681

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:5710:0:b0:3e6:6502:16a5 with SMTP id 16-20020ac85710000000b003e6650216a5mr241283qtw.13.1680825937140;
Thu, 06 Apr 2023 17:05:37 -0700 (PDT)
X-Received: by 2002:a05:622a:1883:b0:3df:58e7:4aa5 with SMTP id
v3-20020a05622a188300b003df58e74aa5mr256492qtc.0.1680825936941; Thu, 06 Apr
2023 17:05:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 6 Apr 2023 17:05:36 -0700 (PDT)
In-Reply-To: <942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.207.255.157; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 82.207.255.157
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com> <942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <151c6f96-c93f-4c5d-9998-0ea6143b88cbn@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Fri, 07 Apr 2023 00:05:37 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Alexandru - Fri, 7 Apr 2023 00:05 UTC

lamuzz...@gmail.com 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.

Re: Put PNG into Windows clipboard

<u0oe22$noca$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21683&group=comp.lang.tcl#21683

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: auriocus@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Fri, 7 Apr 2023 08:43:14 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <u0oe22$noca$1@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com>
<151c6f96-c93f-4c5d-9998-0ea6143b88cbn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 7 Apr 2023 06:43:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0011f9003e5af77c7a03f904c9d30682";
logging-data="778634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Dd/TRocPk/sw3a4mzUHmvbaLWcEZPKyI="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.9.1
Cancel-Lock: sha1:mocT9lqkzPPWV3qEFpf5BWAdj3g=
In-Reply-To: <151c6f96-c93f-4c5d-9998-0ea6143b88cbn@googlegroups.com>
 by: Christian Gollwitzer - Fri, 7 Apr 2023 06:43 UTC

Am 07.04.23 um 02:05 schrieb Alexandru:
> lamuzz...@gmail.com 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

Re: Put PNG into Windows clipboard

<u0oobm$p3r7$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21686&group=comp.lang.tcl#21686

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Fri, 7 Apr 2023 11:39:04 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <u0oobm$p3r7$2@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 7 Apr 2023 09:39:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ee8a9eef1f2cdf3267a03ab9157fd0e0";
logging-data="823143"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RBPFmNOdv1g2DgXUmq5aD"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:DGx9Ez4SHDOVh1eeqBSil9V1b44=
Content-Language: en-GB
In-Reply-To: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
 by: Harald Oehlmann - Fri, 7 Apr 2023 09:39 UTC

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 thanks
> Alexandru

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.
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

Re: Put PNG into Windows clipboard

<d4facbd2-0aef-4d6b-a77f-eebfe85768edn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21687&group=comp.lang.tcl#21687

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:1809:b0:3db:cd1b:e227 with SMTP id t9-20020a05622a180900b003dbcd1be227mr465044qtc.6.1680860487148;
Fri, 07 Apr 2023 02:41:27 -0700 (PDT)
X-Received: by 2002:a05:620a:4593:b0:74a:598b:9241 with SMTP id
bp19-20020a05620a459300b0074a598b9241mr299185qkb.10.1680860486935; Fri, 07
Apr 2023 02:41:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 7 Apr 2023 02:41:26 -0700 (PDT)
In-Reply-To: <u0oe22$noca$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.207.255.128; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 82.207.255.128
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<942e7636-8118-40d5-8d90-dc65fac4060fn@googlegroups.com> <151c6f96-c93f-4c5d-9998-0ea6143b88cbn@googlegroups.com>
<u0oe22$noca$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d4facbd2-0aef-4d6b-a77f-eebfe85768edn@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Fri, 07 Apr 2023 09:41:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2038
 by: Alexandru - Fri, 7 Apr 2023 09:41 UTC

Christian Gollwitzer schrieb am Freitag, 7. April 2023 um 08:43:19 UTC+2:
> Am 07.04.23 um 02:05 schrieb Alexandru:
> > lamuzz...@gmail.com 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
Yes, I realize this too.
I tried to reverse the procedure using this
::twapi::write_clipboard 49406 [$imgname data -format png]
but nothing happens, not even an error.

Re: Put PNG into Windows clipboard

<069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21688&group=comp.lang.tcl#21688

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:198d:b0:3e2:efb6:9d9e with SMTP id u13-20020a05622a198d00b003e2efb69d9emr633035qtc.0.1680860584008;
Fri, 07 Apr 2023 02:43:04 -0700 (PDT)
X-Received: by 2002:ad4:57c1:0:b0:5e6:594d:fbb7 with SMTP id
y1-20020ad457c1000000b005e6594dfbb7mr381461qvx.4.1680860583885; Fri, 07 Apr
2023 02:43:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 7 Apr 2023 02:43:03 -0700 (PDT)
In-Reply-To: <u0oobm$p3r7$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.207.255.128; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 82.207.255.128
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com> <u0oobm$p3r7$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Fri, 07 Apr 2023 09:43:04 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Alexandru - Fri, 7 Apr 2023 09:43 UTC

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:
> > 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
> 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.
> 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?

Re: Put PNG into Windows clipboard

<u0opjo$p3r7$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21689&group=comp.lang.tcl#21689

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Fri, 7 Apr 2023 12:00:26 +0200
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <u0opjo$p3r7$3@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me>
<069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 7 Apr 2023 10:00:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ee8a9eef1f2cdf3267a03ab9157fd0e0";
logging-data="823143"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+z6+8fMmsVrjqx7MJUisE"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:sgdoqxQKqqx6di4Jzan8wZxTcc0=
In-Reply-To: <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
Content-Language: en-GB
 by: Harald Oehlmann - Fri, 7 Apr 2023 10:00 UTC

Am 07.04.2023 um 11:43 schrieb Alexandru:
> 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:
>>> 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
>> 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.
>> 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

Re: Put PNG into Windows clipboard

<00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21690&group=comp.lang.tcl#21690

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:448d:b0:748:753c:b6a4 with SMTP id x13-20020a05620a448d00b00748753cb6a4mr349028qkp.9.1680864288254;
Fri, 07 Apr 2023 03:44:48 -0700 (PDT)
X-Received: by 2002:ac8:5bd1:0:b0:3e6:4c93:3e5c with SMTP id
b17-20020ac85bd1000000b003e64c933e5cmr739385qtb.8.1680864288137; Fri, 07 Apr
2023 03:44:48 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 7 Apr 2023 03:44:47 -0700 (PDT)
In-Reply-To: <u0opjo$p3r7$3@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=82.207.255.128; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 82.207.255.128
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me> <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Fri, 07 Apr 2023 10:44:48 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Alexandru - Fri, 7 Apr 2023 10:44 UTC

Harald Oehlmann schrieb am Freitag, 7. April 2023 um 12:00:30 UTC+2:
> Am 07.04.2023 um 11:43 schrieb Alexandru:
> > 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:
> >>> 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
> >> 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.
> >> 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
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.

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"
}

Re: Put PNG into Windows clipboard

<u0sjla$1d17f$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21691&group=comp.lang.tcl#21691

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: obermeier@poSoft.de (Paul Obermeier)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Sat, 8 Apr 2023 22:43:24 +0200
Organization: A noiseless patient Spider
Lines: 147
Message-ID: <u0sjla$1d17f$1@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me>
<069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me>
<00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 8 Apr 2023 20:43:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3c4e36058bd7e743ea13de2276b3eaf9";
logging-data="1475823"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0fFfrJ2NshAOG90F7/yLnpeItswLvjq4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:gPxtC9DJtnCcA37LlYrRJ0YQirI=
In-Reply-To: <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
 by: Paul Obermeier - Sat, 8 Apr 2023 20:43 UTC

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:
>>> 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:
>>>>> 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
>>>> 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.
>>>> 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
> 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.
>
> 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 following script copies and pastes images with alpha channel.
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

Re: Put PNG into Windows clipboard

<06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21708&group=comp.lang.tcl#21708

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:1a8f:b0:3e2:7190:57ba with SMTP id s15-20020a05622a1a8f00b003e2719057bamr5071980qtc.3.1681223986096;
Tue, 11 Apr 2023 07:39:46 -0700 (PDT)
X-Received: by 2002:ac8:57cf:0:b0:3e7:dcec:92db with SMTP id
w15-20020ac857cf000000b003e7dcec92dbmr175181qta.9.1681223985873; Tue, 11 Apr
2023 07:39:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 11 Apr 2023 07:39:45 -0700 (PDT)
In-Reply-To: <u0sjla$1d17f$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.134.232.45; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 24.134.232.45
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me> <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me> <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Tue, 11 Apr 2023 14:39:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6734
 by: Alexandru - Tue, 11 Apr 2023 14:39 UTC

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:
> >>> 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:
> >>>>> 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
> >>>> 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.
> >>>> 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
> > 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.
> >
> > 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 following script copies and pastes images with alpha channel.
> 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 into PowerPoint and nothing happens. It's like the clipboard were empty, which is not.

Re: Put PNG into Windows clipboard

<c313ca79-1cfb-4c6b-8929-fd5ed25ce671n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21709&group=comp.lang.tcl#21709

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:d89:b0:745:6afc:9bb2 with SMTP id q9-20020a05620a0d8900b007456afc9bb2mr3920920qkl.14.1681241047408;
Tue, 11 Apr 2023 12:24:07 -0700 (PDT)
X-Received: by 2002:ac8:570e:0:b0:3e4:e076:c4a9 with SMTP id
14-20020ac8570e000000b003e4e076c4a9mr1231416qtw.10.1681241047168; Tue, 11 Apr
2023 12:24:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 11 Apr 2023 12:24:06 -0700 (PDT)
In-Reply-To: <u144ja$2m90i$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.134.232.45; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 24.134.232.45
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me> <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me> <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me> <06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
<u144ja$2m90i$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c313ca79-1cfb-4c6b-8929-fd5ed25ce671n@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Tue, 11 Apr 2023 19:24:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 7677
 by: Alexandru - Tue, 11 Apr 2023 19:24 UTC

Paul Obermeier schrieb am Dienstag, 11. April 2023 um 19:15:28 UTC+2:
> Am 11.04.2023 um 16:39 schrieb Alexandru:
> > 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:
> >>>>> 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:
> >>>>>>> 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
> >>>>>> 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.
> >>>>>> 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
> >>> 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.
> >>>
> >>> 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 following script copies and pastes images with alpha channel.
> >> 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 into PowerPoint and nothing happens. It's like the clipboard were empty, which is not.
> 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 Paul, I tried again with CF_PNG=49494 and still the same result.
Where do you get those numbers from? I couldn't find anything in the oficial Microsoft documentation.

Re: Put PNG into Windows clipboard

<78d29f10-49eb-4b3a-9b81-fdd0184a8076n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21710&group=comp.lang.tcl#21710

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:4082:b0:744:1072:e127 with SMTP id f2-20020a05620a408200b007441072e127mr1426733qko.0.1681255192078;
Tue, 11 Apr 2023 16:19:52 -0700 (PDT)
X-Received: by 2002:ad4:55cb:0:b0:5e6:76a:9374 with SMTP id
bt11-20020ad455cb000000b005e6076a9374mr202514qvb.6.1681255191793; Tue, 11 Apr
2023 16:19:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 11 Apr 2023 16:19:51 -0700 (PDT)
In-Reply-To: <c313ca79-1cfb-4c6b-8929-fd5ed25ce671n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=190.139.63.124; posting-account=Cgy5dQoAAADca6APzXXyHNx6hvwj5mk6
NNTP-Posting-Host: 190.139.63.124
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me> <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me> <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me> <06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
<u144ja$2m90i$1@dont-email.me> <c313ca79-1cfb-4c6b-8929-fd5ed25ce671n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <78d29f10-49eb-4b3a-9b81-fdd0184a8076n@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: lamuzzachiodi@gmail.com (lamuzz...@gmail.com)
Injection-Date: Tue, 11 Apr 2023 23:19:52 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2244
 by: lamuzz...@gmail.com - Tue, 11 Apr 2023 23:19 UTC

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

Re: Put PNG into Windows clipboard

<u144ja$2m90i$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21711&group=comp.lang.tcl#21711

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: obermeier@poSoft.de (Paul Obermeier)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Tue, 11 Apr 2023 19:15:24 +0200
Organization: A noiseless patient Spider
Lines: 157
Message-ID: <u144ja$2m90i$1@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me>
<069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me>
<00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me>
<06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 11 Apr 2023 17:15:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="71e2689478e156e5b05d9547c3ebd639";
logging-data="2827282"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L/J/+L4lgd/6Gi4nzbR9WYoe4NMKUPv8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.1
Cancel-Lock: sha1:26cFQcnve4Kc3qhfnwNw2RKrEPc=
In-Reply-To: <06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
 by: Paul Obermeier - Tue, 11 Apr 2023 17:15 UTC

Am 11.04.2023 um 16:39 schrieb Alexandru:
> 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:
>>>>> 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:
>>>>>>> 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
>>>>>> 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.
>>>>>> 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
>>> 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.
>>>
>>> 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 following script copies and pastes images with alpha channel.
>> 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 into PowerPoint and nothing happens. It's like the clipboard were empty, which is not.

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

Re: Put PNG into Windows clipboard

<2d2c2c07-ee3c-4855-8d98-1b071ab36b62n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21714&group=comp.lang.tcl#21714

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:104c:b0:3d5:49eb:4d1e with SMTP id f12-20020a05622a104c00b003d549eb4d1emr1830056qte.1.1681277602654;
Tue, 11 Apr 2023 22:33:22 -0700 (PDT)
X-Received: by 2002:a05:622a:289:b0:3de:bafb:82bf with SMTP id
z9-20020a05622a028900b003debafb82bfmr5423400qtw.4.1681277602463; Tue, 11 Apr
2023 22:33:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 11 Apr 2023 22:33:22 -0700 (PDT)
In-Reply-To: <78d29f10-49eb-4b3a-9b81-fdd0184a8076n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.134.232.45; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 24.134.232.45
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me> <069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me> <00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me> <06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
<u144ja$2m90i$1@dont-email.me> <c313ca79-1cfb-4c6b-8929-fd5ed25ce671n@googlegroups.com>
<78d29f10-49eb-4b3a-9b81-fdd0184a8076n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2d2c2c07-ee3c-4855-8d98-1b071ab36b62n@googlegroups.com>
Subject: Re: Put PNG into Windows clipboard
From: alexandru.dadalau@meshparts.de (Alexandru)
Injection-Date: Wed, 12 Apr 2023 05:33:22 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3111
 by: Alexandru - Wed, 12 Apr 2023 05:33 UTC

lamuzz...@gmail.com schrieb am Mittwoch, 12. April 2023 um 01:19:54 UTC+2:
> 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

Thanks Alejandro,

I will definitely look into that.

Paul also sent me a partial solution that works with most Windows programs, but not with IrfanView. It all depends on that CL_FORMAT, so Paul wrote a function that find out what the current PNG format is (it can change after a computer restart):

proc ClipcoardFormatFind {fmtName} {
for {set fmtNum 1} {$fmtNum<100000} {incr fmtNum} {
set retVal [catch {twapi::get_registered_clipboard_format_name $fmtNum} name]
if {$retVal==0} {
if {$name eq $fmtName} {
return $fmtNum
}
}
}
return -1
}

Now I must find out, how I can make it work also with IrfanView.
The clipboard inspection programs you proposed should help.

Regards
Alexandru

Re: Put PNG into Windows clipboard

<u19eq8$12rib$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21745&group=comp.lang.tcl#21745

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Put PNG into Windows clipboard
Date: Thu, 13 Apr 2023 13:40:23 -0400
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <u19eq8$12rib$1@dont-email.me>
References: <cb3fc502-9596-4e71-a172-470c187ec013n@googlegroups.com>
<u0oobm$p3r7$2@dont-email.me>
<069ae202-8e17-401f-98e5-7e1a39ef5209n@googlegroups.com>
<u0opjo$p3r7$3@dont-email.me>
<00779282-5f99-4abb-9240-66b6a5b5d51an@googlegroups.com>
<u0sjla$1d17f$1@dont-email.me>
<06e5a27c-b859-4205-b932-1084b3741ef7n@googlegroups.com>
<u144ja$2m90i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 13 Apr 2023 17:40:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ba378cbfbd22ffe1715708479a93ebf7";
logging-data="1142347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GV47TvHRhuP2SXduiS2lL"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:OJBgiFQ0FTnngrAKtpEcpZmEyJQ=
In-Reply-To: <u144ja$2m90i$1@dont-email.me>
Content-Language: en-US
 by: saitology9 - Thu, 13 Apr 2023 17:40 UTC

On 4/11/2023 1:15 PM, Paul Obermeier wrote:
>
> 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
>

I can confirm that the latest version you posted on the wiki works fine!
I think I am going to copy it and maybe use it soon.

Thanks!


devel / comp.lang.tcl / Put PNG into Windows clipboard

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor