Skip to content

Commit

Permalink
Note about IImage.Save (#2019)
Browse files Browse the repository at this point in the history
* Note about IImage.Save

* Add comment.

* Edit.
  • Loading branch information
davidbritch authored Jan 17, 2024
1 parent 704d565 commit ceee409
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/user-interface/graphics/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ if (image != null)
using (MemoryStream memStream = new MemoryStream())
{
newImage.Save(memStream);
// Reset destination stream position to 0 if saving to a file
}
}
```

::: moniker-end

In this example, the image is retrieved from the assembly and loaded as a stream. The image is downsized using the <xref:Microsoft.Maui.Graphics.IImage.Downsize%2A> 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 <xref:Microsoft.Maui.Graphics.IImage.Save%2A> method doesn't reset the stream position to 0. Therefore, if you want to save the stream to a file you should use the <xref:System.IO.Stream.Seek%2A> method to reset the destination stream position to 0 before copying it to a file.

0 comments on commit ceee409

Please sign in to comment.