From 1face8f493fd00906b61345afb0a6ca4abf3b6f9 Mon Sep 17 00:00:00 2001 From: Rob Young Date: Fri, 5 Jun 2020 19:51:15 +0100 Subject: [PATCH] Direct user to DynamicImage for converting Attempts to address the documentation suggestion in #1252 A lot of the methods for modifying an image are found in the ImageBuffer so that is where I was looking when trying to convert an image to a different Pixel type. --- src/buffer.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/buffer.rs b/src/buffer.rs index 70e229e686..dec00cdbb2 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -416,6 +416,8 @@ where /// [`RgbImage`]: type.RgbImage.html /// [`GrayImage`]: type.GrayImage.html /// +/// To convert between images of different Pixel types use [`DynamicImage`]: enum.DynamicImage.html +/// /// ## Examples /// /// Create a simple canvas and paint a small cross. @@ -449,6 +451,15 @@ where /// /// image::imageops::overlay(&mut img, &on_top, 128, 128); /// ``` +/// +/// Convert an RgbaImage to a GrayImage. +/// +/// ```no_run +/// use image::{open, DynamicImage}; +/// +/// let rgba = open("path/to/some.png").unwrap().into_rgba(); +/// let gray = DynamicImage::ImageRgba8(rgba).into_luma(); +/// ``` #[derive(Debug, Hash, PartialEq, Eq)] pub struct ImageBuffer { width: u32,