diff --git a/forms/source/component/imgprod.cxx b/forms/source/component/imgprod.cxx index 51961d86682d..c1b72d90daed 100644 --- a/forms/source/component/imgprod.cxx +++ b/forms/source/component/imgprod.cxx @@ -206,7 +206,7 @@ void ImageProducer::SetImage( const OUString& rPath ) if ( ::svt::GraphicAccess::isSupportedURL( maURL ) ) { - mpStm.reset( ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL ) ); + mpStm = ::svt::GraphicAccess::getImageStream( ::comphelper::getProcessComponentContext(), maURL ); } else if( !maURL.isEmpty() ) { diff --git a/include/svtools/imageresourceaccess.hxx b/include/svtools/imageresourceaccess.hxx index 65806566936d..6adff39ae4aa 100644 --- a/include/svtools/imageresourceaccess.hxx +++ b/include/svtools/imageresourceaccess.hxx @@ -50,7 +50,7 @@ SVT_DLLPUBLIC bool isSupportedURL(OUString const & rURL); the image must be copied), so you are strongly encouraged to only use it when you know that the image is small enough. */ -SVT_DLLPUBLIC SvStream* getImageStream( +SVT_DLLPUBLIC std::unique_ptr getImageStream( css::uno::Reference const & rxContext, OUString const & rImageResourceURL); diff --git a/svtools/source/misc/imageresourceaccess.cxx b/svtools/source/misc/imageresourceaccess.cxx index b8a27dd7a802..829ffdb5feb5 100644 --- a/svtools/source/misc/imageresourceaccess.cxx +++ b/svtools/source/misc/imageresourceaccess.cxx @@ -111,9 +111,9 @@ bool isSupportedURL(OUString const & rURL) || rURL.startsWith("vnd.sun.star.extension://"); } -SvStream* getImageStream(uno::Reference const & rxContext, OUString const & rImageResourceURL) +std::unique_ptr getImageStream(uno::Reference const & rxContext, OUString const & rImageResourceURL) { - SvStream* pReturn = nullptr; + std::unique_ptr pMemBuffer; try { @@ -128,10 +128,10 @@ SvStream* getImageStream(uno::Reference const & rxContex OSL_ENSURE(xGraphic.is(), "GraphicAccess::getImageStream: the provider did not give us a graphic object!"); if (!xGraphic.is()) - return pReturn; + return pMemBuffer; // copy the graphic to an in-memory buffer - SvMemoryStream* pMemBuffer = new SvMemoryStream; + pMemBuffer.reset(new SvMemoryStream); uno::Reference xBufferAccess = new StreamSupplier( new OSeekableInputStreamWrapper(*pMemBuffer), new OSeekableOutputStreamWrapper(*pMemBuffer)); @@ -144,19 +144,19 @@ SvStream* getImageStream(uno::Reference const & rxContex xProvider->storeGraphic(xGraphic, aMediaProperties); pMemBuffer->Seek(0); - pReturn = pMemBuffer; } catch (const uno::Exception&) { OSL_FAIL("GraphicAccess::getImageStream: caught an exception!"); + pMemBuffer.reset(); } - return pReturn; + return pMemBuffer; } uno::Reference getImageXStream(uno::Reference const & rxContext, OUString const & rImageResourceURL) { - return new OSeekableInputStreamWrapper(getImageStream(rxContext, rImageResourceURL), true); // take ownership + return new OSeekableInputStreamWrapper(getImageStream(rxContext, rImageResourceURL).release(), true); // take ownership } } // namespace GraphicAccess