views:

1196

answers:

2

An image is copied from Firefox into the Clipboard. My program gets it from clipboard and saves as a JPEG image. For some reason the image is saved with a black background. If I open the same URL in IE and copy the image into the Clipboard, the image is saved correctly by my program. I am using Delphi 7.

I also tried to copy the image from Firefox into Microsoft Paint and again the black background. Does anyone has a tip in how to handle such problem.

+2  A: 

I assume the original image is transparent? If so, you should be aware that JPEGs can't handle transparency. Try switching the output image type and seeing if you program magically goes away.

Pod
Does not work. I tried saving to PNG and GIF to no avail. The problem lies when the DIB is loaded in a TPicture. Somehow I must determine it the image has transparency or not and handle it. That's my question.
Eduardo Mauro
TBH, I don't see why you're copying things to clipboards and such -- can't you just fetch the image from the url, thus cutting out the firefox middle man, which is potentially causing problems?
Pod
My program acts as a clipboard catcher. He does not see Firefox but what is in the Clipboard. The problem is how to handle an image copied from Firefox.
Eduardo Mauro
+1  A: 

If you get the same background in your program and Paint, then that tells me this is something to do with Firefox, and thus it is not necessarily your problem to solve.

Since you're concerned about the background color, I guess the image you're copying has transparent elements to it. So tell me: What color should be there? A JPEG image can't have transparent parts, so every pixel must have some color. Firefox apparently chooses to put black there; how is that not a correct choice and Internet Explorer's is?

I wonder what color background you get when you paste into a more capable graphics program than Paint, such as Gimp or Photoshop. I would expect those programs to consider multiple clipboard formats and choose the most appropriate format, so they might choose a format that accommodates transparency when it's available. Your program and Paint, on the other hand, probably just use the cf_Bitmap format, which of course can't have transparent pixels, so they get whatever the copying program opted to use to fill in the blank space.

By the way, both Firefox and Internet Explorer allow you to drag an image directly from the browser to the desktop or other folder window to save the original image. Maybe that makes your program unnecessary?

Rob Kennedy
Rob, my program catches the clipboard content when something is copied into it. Firefox just puts the image in two formats, DIB and another one I don't remember right now. I am dealing with the DIB one.
Eduardo Mauro
What's the other format?
Rob Kennedy
Rob, I don't know if here is the right place to answer your question. I am new at StackOverflow. The other format that Firefox puts in the Clipboard seems a native one: application/x-moz-nativeimage. I have to stick to CF_DIB.
Eduardo Mauro