/// <summary> /// Submits a request for execution and returns an IDataSource /// representing the pending encoded image(s). /// /// <para />The ResizeOptions in the imageRequest will be /// ignored for this fetch. /// /// <para />The returned IDataSource must be closed once the /// client has finished with it. /// </summary> /// <param name="imageRequest"> /// The request to submit. /// </param> /// <param name="callerContext"> /// The caller context for image request. /// </param> /// <returns> /// An IDataSource representing the pending encoded image(s). /// </returns> public IDataSource <CloseableReference <IPooledByteBuffer> > FetchEncodedImage( ImageRequest imageRequest, object callerContext) { Preconditions.CheckNotNull(imageRequest.SourceUri); try { IProducer <CloseableReference <IPooledByteBuffer> > producerSequence = _producerSequenceFactory.GetEncodedImageProducerSequence(imageRequest); // The resize options are used to determine whether images are going to be // downsampled during decode or not. For the case where the image has to be // downsampled and it's a local image it will be kept as a FileStream until // decoding instead of reading it in memory. Since this method returns an // encoded image, it should always be read into memory. Therefore, the resize // options are ignored to avoid treating the image as if it was to be // downsampled during decode. if (imageRequest.ResizeOptions != null) { imageRequest = ImageRequestBuilder.FromRequest(imageRequest) .SetResizeOptions(null) .Build(); } return(SubmitFetchRequest( producerSequence, imageRequest, new RequestLevel(RequestLevel.FULL_FETCH), callerContext)); } catch (Exception exception) { return(DataSources.ImmediateFailedDataSource <CloseableReference <IPooledByteBuffer> >( exception)); } }