From ceee409b02ce7374c60c0de2d5b29be06c7d889e Mon Sep 17 00:00:00 2001 From: David Britch Date: Wed, 17 Jan 2024 10:50:05 +0000 Subject: [PATCH] Note about IImage.Save (#2019) * Note about IImage.Save * Add comment. * Edit. --- docs/user-interface/graphics/images.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/user-interface/graphics/images.md b/docs/user-interface/graphics/images.md index b7308f0c7..58b89df86 100644 --- a/docs/user-interface/graphics/images.md +++ b/docs/user-interface/graphics/images.md @@ -287,6 +287,7 @@ if (image != null) using (MemoryStream memStream = new MemoryStream()) { newImage.Save(memStream); + // Reset destination stream position to 0 if saving to a file } } ``` @@ -294,3 +295,6 @@ if (image != null) ::: moniker-end In this example, the image is retrieved from the assembly and loaded as a stream. The image is downsized using the method, with the argument specifying that its largest dimension should be set to 150 pixels. In addition, the source image is disposed. The downsized image is then saved to a stream. + +> [!IMPORTANT] +> The method doesn't reset the stream position to 0. Therefore, if you want to save the stream to a file you should use the method to reset the destination stream position to 0 before copying it to a file.