How to implement IReadStream interface with MemoryStream (C#)

See below a simple implementation of IImageSource using MemoryStream which can be used directly from FlexiCaptureProcessor via SetCustomImageSource: 

// IReadStream interface is the interface for a read stream. This interface and all its methods are implemented on the client side. A read stream may be implemented as reading from file. 
class ImageSourceFromStream : IImageSource, IFileAdapter, IReadStream{
    public ImageSourceFromStream( Stream _stream ) {
        stream = _stream;
    }

    // IImageSource  
    public string GetName() {
        return "Stream";
    }

    public IFileAdapter GetNextImageFile()  {
        if( stream != null ) {      
            return this;    
        }  
        return null;
    }

    public IImage GetNextImage() {
        return null;
    }    

    // IFileAdapter  
    public FileMarshallingTypeEnum GetMarshallingType() {
        return FileMarshallingTypeEnum.FMT_MarshalByValue;
    }

    public string GetFileReference() {
         return "";
    }

    public IReadStream GetFileStream() {
        return this;
    }

    // IReadStream  public int Read( out byte[] data, int count ) {
        data = new byte[count];  
        int len = stream.Read( data, 0, count );  
        return len;
    }

    public void Close() {  
        stream = null;  
    }
};

Was this article helpful?

0 out of 2 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.