Packages

 

com.aspose.imaging.sources

Class StreamSource



  • public final class StreamSource
    extends Source

    Represents a stream source.

    Code example:

    This example demonstrates how to use StreamSource to create a new Image file (a JPEG type)


    
    //Creates an instance of JpegOptions and set its various properties
    com.aspose.imaging.imageoptions.JpegOptions jpegOptions = new com.aspose.imaging.imageoptions.JpegOptions();
    
    //Create an instance of System.IO.Stream
    java.io.InputStream stream = new java.io.FileInputStream("C:\\temp\\sample.jpeg");
    
    // Define the source property for the instance of JpegOptions
    // Second boolean parameter determines if the Stream is disposed once get out of scope
    jpegOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream, true));
    
    // Creates an instance of Image and call Create method with JpegOptions as parameter to initialize the Image object
    com.aspose.imaging.Image image = com.aspose.imaging.Image.create(jpegOptions, 500, 500);
    try {
        // Do some image processing
    } finally {
        image.dispose();
    }
    

    • Constructor Detail

      • StreamSource

        public StreamSource(com.aspose.ms.System.IO.Stream stream)

        Initializes a new instance of the StreamSource class.

        Parameters:
        stream - The stream to open.
      • StreamSource

        public StreamSource(byte[] data)

        Initializes a new instance of the StreamSource class.

        Parameters:
        data - byte array which is stored the image
      • StreamSource

        public StreamSource(ByteBuffer buffer)

        Initializes a new instance of the StreamSource class.

        Parameters:
        buffer - ByteBuffer buffer for storing the image
      • StreamSource

        public StreamSource()

        Initializes a new instance of the StreamSource class with Null stream. This constructor allows to create new images without input stream, images stored only in memory.

      • StreamSource

        public StreamSource(RandomAccessFile file)

        Initializes a new instance of the StreamSource class.

        Parameters:
        file - The file to open.
      • StreamSource

        public StreamSource(RandomAccessFile file,
                            boolean disposeStream)

        Initializes a new instance of the StreamSource class.

        Parameters:
        file - The file to open.
        disposeStream - if set to true the stream will be disposed.
      • StreamSource

        public StreamSource(com.aspose.ms.System.IO.Stream stream,
                            boolean disposeStream)

        Initializes a new instance of the StreamSource class.

        Parameters:
        stream - The stream
        disposeStream - if set to true the stream will be disposed.
      • StreamSource

        @Deprecated
        public StreamSource(InputStream stream,
                                         boolean disposeStream)
        Deprecated. Will be removed for it is not possible to write image into InputStream, so it is simply wasted. Instead please use StreamSource.StreamSource(RandomAccessFile,boolean)

        Initializes a new instance of the StreamSource class.

        Parameters:
        stream - The stream to open.
        disposeStream - if set to true the stream will be disposed.
        Code example:

        This example demonstrates how to use StreamSource to create a new Image file (a JPEG type)


        
        //Creates an instance of JpegOptions and set its various properties
        com.aspose.imaging.imageoptions.JpegOptions jpegOptions = new com.aspose.imaging.imageoptions.JpegOptions();
        
        //Create an instance of System.IO.Stream
        java.io.InputStream stream = new java.io.FileInputStream("C:\\temp\\sample.jpeg");
        
        // Define the source property for the instance of JpegOptions
        // Second boolean parameter determines if the Stream is disposed once get out of scope
        jpegOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream, true));
        
        // Creates an instance of Image and call Create method with JpegOptions as parameter to initialize the Image object
        com.aspose.imaging.Image image = com.aspose.imaging.Image.create(jpegOptions, 500, 500);
        try {
            // Do some image processing
        } finally {
            image.dispose();
        }
        

    • Method Detail

      • getStream

        public com.aspose.ms.System.IO.Stream getStream()

        Gets the stream.

        Returns:
        The stream.
      • getDisposeStream

        public boolean getDisposeStream()

        Gets a value indicating whether stream should be disposed whenever container gets disposed.

        Returns:
        true if stream should be disposed; otherwise, false.
      • getStreamContainer

        public StreamContainer getStreamContainer()

        Gets the stream container.

        Specified by:
        getStreamContainer in class Source
        Returns:
        the stream container.

        Use with caution. You will need to dispose the stream container after retrieval.