Home : Image Processing : Make a Custom Image Source
Q10311 - HOWTO: Make a Custom Image Source

This article will demonstrate all of the methods that need to be overridden in order to create your own RandomAccessImageSource object. It will concretely be implementing a RandomAccessImageSource based on reading images from a TiffDocument object.   

 

class TiffDocumentImageSource : RandomAccessImageSource

    {

 

        TiffDocument doc;

        int currentindex;

 

        public TiffDocumentImageSource(TiffDocument tiff)

        {

            doc = tiff;

            currentindex = 0;

        }

 

 

 

 

LowLevelAcquire is the most important method in the ImageSource. Its responsibility is to return the ImageSourceNode that contains the AtalaImage that is loaded.

        protected override ImageSourceNode LowLevelAcquire(int index)

        {

            doc.Pages[index].Stream.Position = 0;

            ImageSourceNode node = new ImageSourceNode(new AtalaImage(doc.Pages[index].Stream,index, null), null);

            return node;

        }

 

 

LowLevelAcquireNext simply must return the next image in the source. The most simple way to implement is to pass responsibility to the LowLevelAcquire method.

        protected override ImageSourceNode LowLevelAcquireNextImage()

        {

            return LowLevelAcquire(currentindex++);

        }

 

LowLevelDispose is where you would dispose anything that maintained state in your imagesource. In this case there is nothing that needs disposal.

        protected override void LowLevelDispose()

        {

        }

 

LowLevelFlushOnReset simply needs to know if flush should be called when the source is reset. In most situations this should return true.

        protected override bool LowLevelFlushOnReset()

        {

            return true;

        }

LowLevelHasMoreImages  should return true if LowLevelAcquireNextImage would return a legitimate AtalaImage.

        protected override bool LowLevelHasMoreImages()

        {

            return currentindex <= doc.Pages.Count;

        }

 

 

LowLevelReset needs to reset any internal variables needing to be reset

        protected override void LowLevelReset()

        {

            currentindex = 0;

        }

 

LowLevelSkipNextImage needs to cause LowLevelAcquireNextImage to skip over an image

        protected override void LowLevelSkipNextImage()

        {

            currentindex++;

        }

 

LowLevelTotalImages needs to return the total number of frames in the source.

        protected override int LowLevelTotalImages()

        {

            return doc.Pages.Count;

        }

    }

Related Articles
No Related Articles Available.

Article Attachments
TiffDocumentImageSource.cs.txt

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2019. InstantASP Ltd. All Rights Reserved