fschultz / NetImageLibrary

Library to help with image handling such as resizing, cropping, applying filters (brightess, contrast, unsharpen mask, chroma key etc), watermarking, thumbnail creation, opening/saving files or streams and more.
http://kaliko.com/image-library/
Other
90 stars 27 forks source link

ChromaKey filter doc #3

Open timkelley66 opened 9 years ago

timkelley66 commented 9 years ago

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

fschultz commented 9 years ago

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! :)

timkelley66 commented 9 years ago

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

fschultz commented 9 years ago

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);