[]
        
(Showing Draft Content)

ImageSource

Class ImageSource

java.lang.Object
com.grapecity.documents.excel.ImageSource

public class ImageSource extends Object
Represents an image source.

An ImageSource stores image data together with its ImageType so it can be supplied to APIs that accept image content. Use getStream() to retrieve the image data as a stream and getType() to retrieve the image format.


 ImageSource imageSource = new ImageSource(createImageStream(), ImageType.PNG);
 worksheet.getOutlineColumn().setCollapseIndicator(imageSource);
 InputStream stream = imageSource.getStream();
 
  • Constructor Details

    • ImageSource

      public ImageSource(InputStream stream, ImageType type)
      Initializes a new image source from an image stream and image type.

      If stream is not null, this constructor reads the stream content and stores it in the image source. The specified type is assigned even when stream is null.

      
       byte[] imageBytes = new byte[] {(byte) 137, 80, 78, 71, 13, 10, 26, 10};
       ImageSource imageSource = new ImageSource(
           new ByteArrayInputStream(imageBytes),
           ImageType.PNG);
       
      Parameters:
      stream - The image stream. If null, no image content is loaded.
      type - The type of the image.
  • Method Details

    • getStream

      public InputStream getStream()
      Gets the image stream.

      Returns a new stream over the stored image bytes when this instance contains image data. If no image data is available, this method returns null.

      
       byte[] imageBytes = new byte[] {(byte) 137, 80, 78, 71, 13, 10, 26, 10};
       ImageSource imageSource = new ImageSource(new ByteArrayInputStream(imageBytes), ImageType.PNG);
       imageSource.getStream();
       
      Returns:
      The image stream, or null if this image source does not contain image data.
    • getType

      public ImageType getType()
      Gets the type of the image.

      Returns the ImageType that was assigned when this image source was created.

      
       byte[] imageBytes = new byte[] {(byte) 137, 80, 78, 71, 13, 10, 26, 10};
       ImageSource imageSource = new ImageSource(
           new ByteArrayInputStream(imageBytes),
           ImageType.PNG);
       ImageType type = imageSource.getType();
       
      Returns:
      The image type. Returns null if no image type was assigned.