Re: Transparent Image Copy to Clipboard Adds Blue BG

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hello,

I'm facing the exact same problems as Bill (albeit for another purpose) and
am not getting anywhere.

I was wondering if you could send me your last changes or tips on this.
--
----
Ben Kooijman



"Michael Phillips, Jr." wrote:

I made changes to your code and provided comments for those changes.

Send me an email with your correct email address and I will send you the
zip.

Of course, you must make changes to my email address to resolve the obvious
spam prevention alterations that are a necessary evil!

Word will correctly identify an alpha channel bitmap and display it,
if you load or drag and drop an image with an alpha channel.

Word will not correctly identify an alpha channel bitmap if it receives
a paste from the clipboard. There are several clipboard formats
available on the clipboard for any application (i.e., CF_BITMAP, CF_DIB,
CF_DIBV5, etc.).

Which format an application requests and uses, is up to the application!

It is a good practice to place CF_BITMAP, CF_DIB and CF_DIBV5 versions of
your
images on the clipboard. If you don't, they will be synthesized by the
clipboard.

Since your application knows ahead of time that the image has an alpha
channel,
placing your version of these clipboard formats obviates the clipboard from
synthesizing the missing formats incorrectly.

It is up to the application to interpret what it receives from the
clipboard! Most applications
don't bother trying to ascertain whether or not an alpha channel bitmap
format is present
on the clipboard. That is why you see a black background in Paint and Word.

They render with an opaque background! Some applications are smart and test
for the presence of an alpha channel. The Microsoft ImageList used on
WindowsXP
is an example.

Happy Holidays
Michael



"Bill Henning" <junk@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eJE1JB9BGHA.2356@xxxxxxxxxxxxxxxxxxxxxxx
Hi Michael,

I'm sorry to be such a pain on this issue, it's just no matter what I try,
it doesn't work right.

You're right that I should have had the BITFIELDS commented out. Also, I
made a mistake in my posting before so let me post all the scenarios
again. I'm starting over with a clean project. I created a tiny sample
project that maybe you could download and try:
http://www.actiprosoftware.com/ClipboardBitmap.zip

It's simply a Form with several buttons on them. It loads and shows a
transparent image on startup and has buttons for copying and pasting. I
have a button for copying using BI_RGB and one for using BI_BITFIELDS. I
have a paste button that uses the API code that we discussed too. Both
the copy and paste use CF_DIBV5. I also have copy/paste buttons for .NET
framework code, but ignore those.

So here's the scenarios using my test app:
1) Copy from my app using BI_RGB and paste in my app: the pasted image
looks perfect.
2) Copy from my app using BI_BITFIELDS and paste in my app: the pasted
image is offset to the right about two pixels and wraps to the left side.
But other than that, it looks good.
3) Copy from my app using BI_RGB and paste in Paint: the pasted image
looks good but has a black background where the transparent region should
be. Maybe Paint just isn't transparency aware, which is actually ok for my
purposes.
4) Copy from my app using BI_BITFIELDS and paste in Paint: the pasted
image is a combination of #2 and #3... it's offset to the right with a
black background. Also there's a little red, green, and then blue pixel
at the bottom. This makes me think it's pulling in the masks data as
bitmap data.
5) Copy from Paint and past in my app: The image looks completely
garbled, like a fuzzy TV.
6) Copy from my app using BI_RGB and paste in Word customize mode for a
button: Same results as #2... image looks good but black background. I
do need transparency working in Word.
7) Copy from my app using BI_BITFIELDS and paste in Word customize mode
for a button: Same results as #4... image is offset with black background
and shows 3 RGB pixels at bottom.
8) Copy from Word customize mode for a button and paste in my app: The
"new Bitmap()" call in my paste method blows up with an "Invalid parameter
used" exception.

Anyhow, that's everything I need to get working. It seems like we're so
close. From the above scenarios, here's the remaining issues as I see
them:
1) My BI_BITFIELDS copy code is slightly wrong somewhere. It seems like
it's reading the wrong area of the bitmap data (in the masks area) and
maybe is therefore off by a scanline or so.
2) Pasting a CF_DIBV5 image from my app into Word doesn't retain
transparency. I need that working one way or another.
3) Pasting from Paint into my app needs fixing since it's all garbled.
4) Pasting from Word into my app needs fixing since it throws an
exception.

I'd really appreciate it if you could check out my sample project and
modify it however necessary to get those things functioning. That's
probably easier than you posting what I should change and then me still
not getting it right with my limited knowledge of this stuff. :)

I'll be happy to post the resulting code in the newsgroup for everyone
else's benefit as well.

Thanks and Happy Holidays,
Bill





.


Quantcast