Search

Atalasoft Knowledge Base

HOWTO: Manipulate Individual Frames in an ImageSource

Administrator
DotImage

When manipulating large files supporting different multipage file encodings become difficult while maintaining small memory use, for this, we have the ImageSource. It keeps as much data out of memory as it can. The difficulty with this is that in some implementations different modifications to different individual images is not simple. To remedy this, the FileSystemImagePipe was created, a class that performs operations on individual frames. Below is an example of setting up the FileSystemImagePipe to take a 3 frame image, replace its first frame with a red rectangle, performs a RotateCommand on the second frame, and deletes the third frame entirely:

C#

using (OpenFileDialog open = new OpenFileDialog())
{
    if (open.ShowDialog() == DialogResult.OK)
    {
	    FileSystemImagePipe pipe = new FileSystemImagePipe(open.FileNames, true);
	    
	    //Add Ops
	    pipe.AddOp(2, new DeleteOp(pipe));
	    pipe.AddOp(1, new CommandPipeOp(new RotateCommand(90)));
	    pipe.AddOp(0, new ReplaceOp(new AtalaImage(200,200,PixelFormat.Pixel24bppBgr, Color.Red)));
	    
	    //Save
	    TiffEncoder tif = new TiffEncoder();
	    using(FileStream outStream = new FileStream("out.tif", FileMode.Create))
	    {
	        tif.Save(outStream, pipe, null);
	    }
	}
}

VB.NET

 
Dim open As New OpenFileDialog()
open.ShowDialog()
Dim pipe As New FileSystemImagePipe(open.FileNames, True)
'Add Ops
pipe.AddOp(2, New DeleteOp(pipe))
pipe.AddOp(1, New CommandPipeOp(New RotateCommand(90)))
pipe.AddOp(0, New ReplaceOp(New AtalaImage(200, 200, PixelFormat.Pixel24bppBgr, Color.Red)))
'Save
Dim tif As New TiffEncoder()
Using outStream As New FileStream("out.tif", FileMode.Create)
    tif.Save(outStream, pipe, Nothing)
End Using

In the attached project there are three PipeOps created:
ReplaceOp – This operation completely replaces one AtalaImage with another
CommandPipeOp – This operation allows use of any ImageCommand class
DeleteOp – This operation removes the frame entirely from the output image

To create a custom PipeOp, implement the PipeOp abstract class and modify the image in the Operate method.

Original Article:
Q10283 - HOWTO: Manipulate Individual Frames in an ImageSource

Details
Last Modified: 6 Years Ago
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 483 times.
Options
Also In This Category