Does EMF (Enhanced Metafile) support opacity? - transparency

I would be able to create an EMF image (programmatically or from a software) having the background color 50% transparent and the other elements completely opaques.
I'm already be able to create a background completely transparent, but not with a certain alpha/opacity.
Creating this semi-transparent background would allow to overlay the image to another background without completely hide it.
Does anyone know if it's possible with the Enhanced Metafile format?

The answer is no: EMF (or WMF) image format supports full transparency but not opacity between 0.0 and 1.0 because it doesn't support colors with alpha channel.
Here are image formats that supports alpha channel

I've been struggling with this topic a few weeks now and my research led me to good results.
Here is information for those who might face this issue in the future:
Windows EMF which uses GDI library does not support transparent colors.
However there is a newer EMF format called EMF+, which uses GDI+ library and supports transparency.
Here is the documentation of the class.
There are quite a few examples for these metafiles in C++ arround the internet, but some experiments can lead you the right way.

Related

Replace particular color of image in iOS

I want to replace the particular color of an image with other user selected color. While replacing color of image, I want to maintain the gradient effect of that original color. for example see the attached images.
I have tried to do so with CoreGraphics & I got success to replace color. But the replacing color do not maintain the gradient effect of the original color in the image.
Can someone help me on this? Is the CoreGraphics is right way to do this?
Thanks in advance.
After some struggling almost with the same problem (but with NSImage), made a category for replacing colors in NSImage which uses ColorCube CIFilter.
https://github.com/braginets/NSImage-replace-color
inspired by this code for UIImage (also uses CIColorCube):
https://github.com/vhbit/ColorCubeSample
I do a lot of color transfer/blend/replacement/swapping between images in my projects and have found the following publications very useful, both by Erik Reinhard:
Color Transfer Between Images
Real-Time Color Blending of Rendered and Captured Video
Unfortunately I can't post any source code (or images) right now because the results are being submitted to an upcoming conference, but I have implemented variations of the above algorithms with very pleasing results. I'm sure with some tweaks (and a bit of patience) you might be able to get what you're after!
EDIT:
Furthermore, the real challenge will lie in separating the different picture elements (e.g. isolating the wall). This is not unlike Photoshop's magic wand tool which obviously requires a lot of processing power and complex algorithms (and is still not perfect).

GIF to AVI with windows Animate Control

I was trying to convert a GIF image (Ajax waiting like):
to AVI that will be used with TAnimate control (win32 animation control).
I have tried a few tools, but the problem is that the output AVI is either not suitable for the Animation control or not transparent.
Notes:
I don't use windows XP Themes manifest (D5).
the Common Avi's are transparent even if my program is not themed.
Using the GIF itself to show animation is not an option.
Do you know any tool that can help me with this conversion?
EDIT:
I have tried using ImageMagic with ffmpeg as described here. but I can't seem to set ffmpeg to encode to msrle.
Jasc Animation Shop is able to directly read an animated GIF and write out a compressed AVI. This is an old program that appears to be no longer offered by Corel (who acquired Jasc), but you may still be able to find the free trial version for example.
You could try the TGIFImage component (written for Delphi 5), which claims not only to support Animated GIFs, but also Transparency, as well as a means of converting a GIF to an AVI (and vice-versa).
Whether it does all that or not I cannot say as I haven't personally tested it. Like TLama mentioned in the OP comments above, I use my own means of playing each frame in an animated fashion (only mine uses a RES file and a TImage, where each frame is stored as a PNG for full semi-transparency support).
Many commercial tools do this conversion, including Corel Photo Paint, and others. A free trial is available for Corel Photo Paint, which comes included in the Corel Draw package. (Warning: It's huge, and expensive.) I don't think the transparency will be solved any more by corel photo paint's conversion than by anybody else.
Typing some words into Google, also reveals that DSPack from ProgDigy might help you.
The last time I did this, I abandoned the attempt to convert GIF transparency into AVI-with-transparency, because no AVI-encoding tool that I could find would preserve transparency. Thus the solution of leaving it as a gif, and putting a new control into your app (as LaKraven suggests) may be superior in the end, to fighting it.
I would suggest using GDIPlus native image renderer which can easily handle animated GIFs as well as many other image types, including multi-frame TIFFs (no MNG so far). I was able to find an example component which animates TImage instance:
http://www.progdigy.com/forums/viewtopic.php?p=13156
Please note I am aware that you are looking for a solution to AVI transparency, this is just an alternative way of presenting user with a "progress", which seems to be more lightweight (no dependency on windows media playback facilities) and flexible (such animation controller can be used on any image).

How I can detect the background of an image programmatically?

I need to develop a software that selects a face from a photo where the background is a plain color (green, like in the movies).
Then we want to compose that selection with another background image, this part is easy with many libraries. But I don't know how can I do the selection? Can you give some links or libraries to investigate? I can do this project with any language of my choose, so examples or links in any language are welcome.
Ok, what you are trying to do is called chroma key. Like you say, it used a lot in the movies with a blue/green screen. On windows its actually pretty easy to do because its built into windows as part of GDI+ (or on C#, I think its just called the Graphics class).
I dont have any sample code handy, but the process is pretty straight forward:
With GDI+, you create a bitmap object of your foreground image (the one with the green background). Then create an ImageAttributes object. Use ImageAttribute's object's SetColorKey() method to specify a color or range of colors to use as the background color. Lastly, draw that bitmap object over the target bitmap, and GDI+ will draw it as if the background color is transparent.
There's more to it in that in code, but concept-wise thats all there is to it.
This is probably an area where it is easier to work in some other space than RGB - such as HSV.
I would also look at the OpenCV library.

How do I print a partially transparent image to a PDF Canvas using Delphi?

My program needs to output a (fairly complex) form to the printer, including several images. I’m currently doing this using Delphi (2006)’s Printer.Canvas, after selecting a PDF printer (PDF995). This works like a treat.
However, I’m now running into a problem: there’s one partially transparent image that needs to be placed on top of other elements (borders, background and such), with portions of that text still visible through parts of the image.
Doing this on a regular screen Canvas works fine with regular TBitmaps, by using the TransparentColor property. However, when I try to do this on a printer, it doesn’t always work; and when I try this on a PDF printer, it never works: the background turns black, or (the best result so far), turns white, but still overwrites anything underneath it.
I’ve tried achieving the same result by inserting a PNG image with alpha transparency (a.k.a. translucency) in a Word document, and then sending that to said PDF printer. The translucency disappears, but pixel transparency is maintained. So that, at least, should somehow be possible.
Anybody know how?
You mention you are using the TransparentColor property, so is it correct to say you don't really need alpha transparency and can get away with using binary transparency (transparency for each pixel is either off or on)?
If so, it might be possible to generate a Region from your bitmap.
You then use this region as a clipping region and draw the bitmap.
The PDF printer might be able to handle a clipping region correctly.
Here's an example of generating a region from a bitmap, it's used to make non-rectangular forms but the idea is the same:
http://www.delphi-central.com/BitmapShapedForm.aspx
Here is another example of setting a clipping region for your TCanvas:
http://www.efg2.com/Lab/OtherProjects/PrinterDemo2.htm
I don't think you can achieve partial transparency using a pdf printer. What you can do is get the VisPDF package. With it you can add a mask to the images contained in the pdf that you actually produce right in you're application. If this is not an option, you could combine all your background stuff in to one image. Drawing the alphachanneled thing on this image.
I also had this problem before, If I recall correctly, what I ended up doing was to create an off screen bitmap that I manipulated, then after I was done copied again and used the new bitmap copy on the canvas I was sending to the printer.
You may want to consider using a third-party PDF component in your application to render the canvas directly to PDF. I use this technique for specialized reporting (RTF, Radioemtric JPEGs, Tables, Text etc) in a commercial product I developed for Infrared Thermography. I am very happy with the performance and quality. The component I am using llPDFLib was just updated and I believe now supports full image transparency.
Best of luck. Printing images with an Alpha channel can be challenging at times in my experience.

Where can I find an image watermark control for Delphi?

Is there a good image watermark control for Delphi? It would be nice if it could receive both text and images to insert in a base photo.
I would also prefer it was free.
I couldn't find any pre-packaged controls. But watermarking is not very hard at all. All you simply need to do is draw an image on top of another image with the use of alpha blending. This site has a whole section on alpha blending in Delphi. They provide links to graphics libraries which have implemented it.
However if you're using Delphi.NET, and can access the relevant classes in the framework, there is an easier way using only framework methods.
Take a look at Graphics32 together with GraphicEX.
Or see if PascalMagick does the trick.

Resources