pub fn rasterize_svg(svg_bytes: &[u8], size: u32) -> Result<IconData>Expand description
Rasterize SVG bytes to RGBA pixel data at the given size.
Parses the SVG, scales it uniformly to fit within size x size pixels
(preserving aspect ratio), and renders to a pixel buffer with straight
(non-premultiplied) alpha.
§Errors
Returns crate::Error::ReaderFailed if the SVG cannot be parsed or
the size is zero / pixmap allocation fails.
§Examples
use native_theme::rasterize::rasterize_svg;
use native_theme::theme::IconData;
let svg = b"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10'/></svg>";
let result = rasterize_svg(svg, 24);
assert!(result.is_ok());
if let Ok(IconData::Rgba { width, height, data }) = result {
assert_eq!(width, 24);
assert_eq!(height, 24);
assert_eq!(data.len(), 24 * 24 * 4);
}