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 : Wednesday, July 26, 2006 4:45:32 AM(UTC)
Dataexpert

Groups: Registered
Posts: 5


Hi,
I need an example on how I can select just a portion of an image (from a RasterImageViewer or directly form a RasterImage) and visualize it in another RasterImageViewer. All as to be done programmatically, the user has to do nothing.
I simply want to "highlight" a spot of my image, of which I know the coordinates, by showing it zoomed in a different viewer.
How can I implement it?

(I'm using LeadTools 14.5 with the dotnet class library in a C# program)

Thanks for you're attention.
 

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.

#2 Posted : Sunday, July 30, 2006 10:26:37 PM(UTC)

Bashar  
Guest

Groups: Guests
Posts: 3,022

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

You need to use the AddRectangleToRegion method and the CombineCommand
class to do this.  You can find a tutorial in the LEADTOOLS for
.NET help file that shows how to do this.  The tutorial is titled "Combining Images With Regions".

 
#3 Posted : Thursday, August 3, 2006 12:16:15 AM(UTC)
Dataexpert

Groups: Registered
Posts: 5


Thanx for your answer Bashar.
I've read the tutorial and trying to make it works for my project i've wrote this code:

            RasterCodecs cdcs = new RasterCodecs();
            IRasterImage RasImg1 = cdcs.Load("BitmapBrush.bmp");
            riv1.Image = RasImg1;

            IRasterImage RasImg2 = cdcs.Load("ULAY1.bmp");
            riv2.Image = RasImg2;

            RasImg1.AddRectangleToRegion(null, new Rectangle(10, 10, 50, 50), RasterRegionCombineMode.Set);

            CombineFastCommand combine = new CombineFastCommand();
            combine.DestinationImage = riv2.Image;
            combine.DestinationRectangle = new Rectangle(0, 0, 5, 5);
            combine.SourcePoint = Point.Empty;
            combine.Flags = CombineFastCommandFlags.OperationAverage;
            combine.Run(RasImg1);

But it doesn't works.... it thrown a RasterException "Invalid parameter passed" on the last instruction. Could you help me find out why?

The code above it's just a test code obviously, the image RasImg1 will be get from a Twain session and the RasterImageViewer riv2 has to be empty and filled just with the choosen part of the riv1 image... is this possible or I have to put in riv2 a fake image?
 
#4 Posted : Friday, August 4, 2006 12:22:43 PM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


I could not reproduce your error, but the command did not seem to combine properly.  I gave your SourcePoint an actual value and then it worked for me.  This will make your SourcePoint equal to the point of the Region on your source image.

combine.SourcePoint = New Point(RasterImageViewer1.Image.GetRegionBounds(Nothing).X, RasterImageViewer1.Image.GetRegionBounds(Nothing).Y)

To answer your other question, you do need an actual image to be able to combine them.  If you need to, use the FillCommand to make it a solid color before combining.

Let me know if all this answers your questions.
 
#5 Posted : Sunday, August 6, 2006 10:43:31 PM(UTC)
Dataexpert

Groups: Registered
Posts: 5


I've modified the code as you suggest but it doesn't works yet...
I've found out that non all the CombineFastCommandFlags are allowed when I'm running my program, doing some checks it results that only "Source0, Source1, Destination0, Result0 and Result1" are available... using one of these the program don't throw an exception but the riv2.Image (my destination img) just become gray or black.


 
#6 Posted : Monday, August 7, 2006 6:56:18 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


What is the exception you are getting and what code is throwing it?  If you want to, put together a very simple sample application with the images you are trying to combine so that I can see what is going on.  In order to attach a file to the forum, it must be a .zip file.  At the least I would like to test your images.

Source0 would make the Source bitmap all 0s (black) and Source1 would make the source bitmap all 1s (white).  Any of the *0 and *1 work the same way depending on what the * is.  If you are getting gray then you are probably combining a black area with a white area.  If you want to make the destination area exactly the same as the source without colors getting changed, you should OR the Desination0 and OperationAdd flags.  This will clear the bitmap of the desination area to all black, and then add the data so that the pixel colors are exactly the same.
 
#7 Posted : Monday, August 7, 2006 10:53:56 PM(UTC)
Dataexpert

Groups: Registered
Posts: 5


I've changed my test images from BMPs to JPGs and now it seems to work... probably combining BMPs is possible just using the flags i wrote above.
There's one more problem, I can select the region I want to "copy" from RasterImageViewer1 and I can "paste" it in RasterImageViewer2 but I cannot stretch it to the whole dimension of the viewer, it always remains of the dimension of the original region...
This is the code I'm using in my tests:

            RasterCodecs cdcs = new RasterCodecs();
            IRasterImage RasImg1 = cdcs.Load("test.JPG");
            riv1.Image = RasImg1;

            IRasterImage RasImg2 = cdcs.Load("test.JPG");
            riv2.Image = RasImg2;
            FillCommand fillCmd = new FillCommand();
            fillCmd.Color = new RasterColor(255, 255, 255);
            fillCmd.Run(riv2.Image);

            RasImg1.AddRectangleToRegion(null, new Rectangle(0, 0, 20, 20), RasterRegionCombineMode.Set);

            CombineFastCommand combine = new CombineFastCommand();
            combine.DestinationImage = riv2.Image;
            combine.DestinationRectangle = new Rectangle(0, 0, riv2.Width, riv2.Height);
            combine.SourcePoint = new Point(riv1.Image.GetRegionBounds(null).X, riv1.Image.GetRegionBounds(null).Y);
            combine.Flags = CombineFastCommandFlags.Destination0|CombineFastCommandFlags.OperationAdd;
            combine.Run(riv1.Image);
 
#8 Posted : Tuesday, August 8, 2006 11:58:33 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


Your second viewer is not being stretched because you are probably pasting a small region into a very large bitmap.  Instead of loading the same file, test.JPG, into both vieweres, your second image should be a new, blank image the same size as the region you are selecting.  This way you can set the SizeMode property to RasterViewerSizeMode.Fit.  Also, in your destination rectangle, make sure you are using riv2.Image.Width and riv2.Image.Height so that you are using the bitmap's width/height rather than the viewer control's width/height.  I have edited your code below:

            RasterCodecs cdcs = new RasterCodecs();
            IRasterImage RasImg1 = cdcs.Load("test.JPG");
            riv1.Image = RasImg1;

            RasImg1.AddRectangleToRegion(null, new Rectangle(0, 0, 20, 20), RasterRegionCombineMode.Set);


            RasterImage RasImg2 = new RasterImage(RasterMemoryFlags.Managed, riv1.Image.GetRegionBounds(Nothing).Width, riv1.Image.GetRegionBounds(Nothing).Height, riv1.Image.BitsPerPixel, riv.Image.Order, riv1.Image.ViewPerspective, riv1.Image.Palette, Nothing);
            riv2.Image = RasImg2;
            FillCommand fillCmd = new FillCommand();
            fillCmd.Color = new RasterColor(255, 255, 255);
            fillCmd.Run(riv2.Image);

            CombineFastCommand combine = new CombineFastCommand();
            combine.DestinationImage = riv2.Image;
            combine.DestinationRectangle = new Rectangle(0, 0, riv2.Image.Width, riv2.Image.Height);
            combine.SourcePoint = new Point(riv1.Image.GetRegionBounds(null).X, riv1.Image.GetRegionBounds(null).Y);
            combine.Flags = CombineFastCommandFlags.Destination0|CombineFastCommandFlags.OperationAdd;
            combine.Run(riv1.Image);
 
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.417 seconds.