Sign in to follow this  
Followers 0
Toli

Possible bug: "The clipboard doesn't contain an image."

12 posts in this topic

False. The Clipboard does contain an image. It is a png and it can be safely pasted into Word or Excel using "Paste Special". It can't be pasted in mspaint though.

0

Share this post


Link to post
Share on other sites

If it's not working in Paint.NET or MSPaint, but it works in Word and Excel, you might have some Office proprietary data in the clipboard, not a regular bitmap image.

Or maybe you copied the image file instead of the image. This is not the same thing.

0

Share this post


Link to post
Share on other sites

It is not the file, it is a png image. I know the difference.

I copy it using .net.

Clipboard.SetData("PNG", image);

image is a standard 32bpp png which opens fine in Paint.NET and renders fine in .net Windows.Forms.

Clipboard.SetImage(image);

does the job, but the image loses its transparency when pasted, so it's of no use.

So, why does Paint.NET not recognize the "PNG" Clipboard format?

0

Share this post


Link to post
Share on other sites

How wierd. I used the usual right click on the post number. Odd.

I meant to link to Rick's post in this thread: Clicky

0

Share this post


Link to post
Share on other sites

Actually Paint.NET is intentionally lying to you. I needed a way to get more people to sign up for the forum so I made it randomly bomb out on copy/paste ...

Just kidding. It's not lying to you. Like I said elsewhere, the clipboard is a shared resource, it's cantankerous, and it's not very smart. Setting the type to "PNG" doesn't mean anything, you're using the wrong tag there.

0

Share this post


Link to post
Share on other sites

But it actualy is a PNG and Word sees it as a valid PNG... so the tag is not wrong

0

Share this post


Link to post
Share on other sites

It is not the file, it is a png image. I know the difference.

I copy it using .net.

Clipboard.SetData("PNG", image);

image is a standard 32bpp png which opens fine in Paint.NET and renders fine in .net Windows.Forms.

Clipboard.SetImage(image);

does the job, but the image loses its transparency when pasted, so it's of no use.

So, why does Paint.NET not recognize the "PNG" Clipboard format?

To properly paste a PNG image to the clipboard, do the following

using (MemoryStream stream = new MemoryStream())

{

_Bitmap.Save(stream, ImageFormat.Png);

var data = new DataObject("PNG", stream);

Clipboard.Clear();

Clipboard.SetDataObject(data, true);

}

This should take care of your problems.

Edited by gregdosborne
0

Share this post


Link to post
Share on other sites

gregdosborne, newer versions of Paint.NET already do this. Using Reflector, look at PaintDotNet.exe, in the PaintDotNet.ClipboardUtil class, in the GetClipboardImageAsSurface() method.

0

Share this post


Link to post
Share on other sites

I kinda feel like a noob saying something that doesn't involve arguing with strings of code, but when I get an error message like that and I can only paste into a word processor, it is usually because I highlighted the image, then copied it. From a non-programmer perspective (and I feel silly saying this), the computer thinks I copied a piece of text and I'm trying to paste it as an image. To solve the problem, I go back, un-highlight the image, and copy by right clicking and pressing the "copy image" button. Not sure if this is the same issue, but it sure sounds like it is.

0

Share this post


Link to post
Share on other sites

Well this conversation is going on elsewhere and this thread is really old anyway, I'm going to close the thread.

0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0