NetImageLibrary icon indicating copy to clipboard operation
NetImageLibrary copied to clipboard

ChromaKey filter doc

Open timkelley66 opened this issue 10 years ago • 3 comments

Do you have any doc on how to use the new chroma key filter (preferably c#).

timkelley66 avatar Jan 02 '15 15:01 timkelley66

Unfortunately I'm a little behind on documenting the API with examples, but until I get around, here's how to use the chroma key filter (chroma.jpg being a green screen image):

var image = new KalikoImage("chroma.jpg");
var filter = new ChromaKeyFilter();
filter.KeyColor = Color.FromArgb(0, 255, 0);
filter.ToleranceHue = 40;
filter.ToleranceSaturnation = 0.7f;
filter.ToleranceBrightness = 0.5f;
image.ApplyFilter(filter);
image.SavePng("actoronly.png");

Set KeyColor to either pure green (which is default) or something pretty close to your background. The value for ToleranceHue (between 0 and 360) tells how far from the key color hue the filter should work, a higher value will remove more around the edges but can cause some cut-away. ToleranceSaturnation and ToleranceBrigthness should be between 0 and 1.

The above values should be a good start, tweak the tolerance values to get a better result.

Hope that helps! :)

fschultz avatar Jan 02 '15 18:01 fschultz

OK. That works great. Does your library have any way for me to take that png file and combine it with a jpg image?

timkelley66 avatar Jan 02 '15 20:01 timkelley66

Yes, you could load your jpg file and use the BlitImage function (http://kaliko.com/image-library/api/kaliko.imagelibrary/kaliko.imagelibrary.kalikoimage/blitimage/) to paste your chroma keyed image on top of it before saving.

Code-wise it would look something like this:

var image = new KalikoImage("chroma.jpg");
var filter = new ChromaKeyFilter();
filter.KeyColor = Color.FromArgb(0, 255, 0);
filter.ToleranceHue = 40;
filter.ToleranceSaturnation = 0.7f;
filter.ToleranceBrightness = 0.5f;
image.ApplyFilter(filter);

var backdrop = new KalikoImage("mybackdrop.jpg");
backdrop.BlitImage(image);

backdrop.SaveJpg("ActorOnBackdrop.jpg", 90);

fschultz avatar Jan 02 '15 21:01 fschultz