Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, October 27, 2016 5:49:03 PM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 367

Was thanked: 1 time(s) in 1 post(s)

The code below takes 2 images as input and fills with green color every pixel in the first image that's identical to the corresponding pixel in the second image.
This C# code works with v19 of LEADTOOLS, as well as numerous other versions.
Code:
//load the 2 images
RasterImage bitmap1 = _codecs.Load("Image1.png");
RasterImage bitmap2 = _codecs.Load("Image2.png");
//pefrom XOR combining to convert similar pixels to black in image2. All non-similar pixels become non-black
LeadRect combineRect = new LeadRect(0, 0, bitmap1.Width, bitmap1.Height);
CombineFastCommand combineCmd = new CombineFastCommand(bitmap2, combineRect, new LeadPoint(0, 0), CombineFastCommandFlags.OperationXor);
combineCmd.Run(bitmap1);
//create a region in image2 with all the black pixels. Those pixels were the similar ones.
bitmap2.AddColorToRegion(RasterColor.Black, RasterRegionCombineMode.Set);
//fill the region with green
FillCommand fillGreen = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Green));
fillGreen.Run(bitmap2);
//perfom copy combining to copy the green pixels to the first image
combineCmd.DestinationImage = bitmap1;
combineCmd.Flags = CombineFastCommandFlags.SourceCopy;
combineCmd.Run(bitmap2);
//Save the result
_codecs.Save(bitmap1, "Result.png", RasterImageFormat.Png, 24);

First image
Image1.png
Second image
Image2.png
Result
Result.png

Edited by user Sunday, May 7, 2017 4:27:34 PM(UTC)  | Reason: Not specified

Amin Dodin

Senior Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.036 seconds.