pub struct CGContext { /* private fields */ }cg only.Expand description
Reference-counted CGContextRef backed by a bitmap.
Clones retain the same mutable native context; they are not independent drawing surfaces.
Implementations§
Source§impl CGContext
impl CGContext
Sourcepub fn bytes_per_row(&self) -> usize
pub fn bytes_per_row(&self) -> usize
Bytes per row.
Sourcepub fn bits_per_component(&self) -> usize
pub fn bits_per_component(&self) -> usize
Bits per component.
Sourcepub fn bits_per_pixel(&self) -> usize
pub fn bits_per_pixel(&self) -> usize
Bits per pixel.
Sourcepub fn data(&self) -> *mut u8
pub fn data(&self) -> *mut u8
Raw bitmap data pointer.
Dereferencing the pointer is unsafe because retained aliases and native drawing operations can mutate the same storage.
Sourcepub fn color_space(&self) -> Option<CGColorSpace>
pub fn color_space(&self) -> Option<CGColorSpace>
The context color space, if one is set.
Sourcepub fn alpha_info(&self) -> u32
pub fn alpha_info(&self) -> u32
The raw CGImageAlphaInfo value for the bitmap context.
Sourcepub unsafe fn as_bytes(&self) -> &[u8] ⓘ
pub unsafe fn as_bytes(&self) -> &[u8] ⓘ
The bitmap storage as immutable bytes.
§Safety
Every byte in the range must already be initialized. For the returned reference’s lifetime, the bitmap allocation must remain live and immovable, and no retained alias or native call may draw into, clear, replace, or otherwise mutate the context storage.
Sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
The bitmap storage as mutable bytes.
§Safety
Every byte in the range must already be initialized. For the returned reference’s lifetime, the caller must have unique access to the bitmap storage across every retained wrapper and native alias, and no drawing or snapshot operation may access the context.
Sourcepub fn set_rgb_fill_color(&self, r: f64, g: f64, b: f64, a: f64)
pub fn set_rgb_fill_color(&self, r: f64, g: f64, b: f64, a: f64)
Set the current fill color in DeviceRGB.
Sourcepub fn set_rgb_stroke_color(&self, r: f64, g: f64, b: f64, a: f64)
pub fn set_rgb_stroke_color(&self, r: f64, g: f64, b: f64, a: f64)
Set the current stroke color in DeviceRGB.
Sourcepub fn set_line_width(&self, w: f64)
pub fn set_line_width(&self, w: f64)
Set the stroke line width.
Sourcepub fn clear_rect(&self, x: f64, y: f64, w: f64, h: f64)
pub fn clear_rect(&self, x: f64, y: f64, w: f64, h: f64)
Clear a rectangle to transparent black.
Sourcepub fn begin_path(&self)
pub fn begin_path(&self)
Begin a new path.
Sourcepub fn close_path(&self)
pub fn close_path(&self)
Close the current path.
Sourcepub fn add_line_to(&self, x: f64, y: f64)
pub fn add_line_to(&self, x: f64, y: f64)
Add a line segment to the current path.
Sourcepub fn add_ellipse_in_rect(&self, x: f64, y: f64, w: f64, h: f64)
pub fn add_ellipse_in_rect(&self, x: f64, y: f64, w: f64, h: f64)
Add an ellipse inscribed in the rectangle.
Sourcepub fn stroke_path(&self)
pub fn stroke_path(&self)
Stroke the current path.
Sourcepub fn draw_image(&self, x: f64, y: f64, w: f64, h: f64, image: &CGImage)
pub fn draw_image(&self, x: f64, y: f64, w: f64, h: f64, image: &CGImage)
Draw an image into the target rectangle.
Sourcepub fn save_g_state(&self)
pub fn save_g_state(&self)
Save the current graphics state.
Sourcepub fn restore_g_state(&self)
pub fn restore_g_state(&self)
Restore the most recently saved graphics state.
Sourcepub fn snapshot_to_image(&self) -> Option<CGImage>
pub fn snapshot_to_image(&self) -> Option<CGImage>
Snapshot the current bitmap contents to a CGImage.