Click or drag to resize

AtalaImageChangePixelFormat Event

Occurs when the image data changes PixelFormats.

Namespace:  Atalasoft.Imaging
Assembly:  Atalasoft.dotImage (in Atalasoft.dotImage.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public static event PixelFormatChangeEventHandler ChangePixelFormat

Value

Type: Atalasoft.ImagingPixelFormatChangeEventHandler
Remarks
This static event is usually fired when a particular method is not compatible with the current PixelFormat and it needs to be changed. By handling this event, you may show a dialog to the user that the current PixelFormat will be changed and allow that operation to be cancelled by setting the Cancel property in the PixelFormatChangeEventArgs to true.
Examples
ChangePixelFormat Example (C#)
// Setup the event handler.
AtalaImage.ChangePixelFormat += new PixelFormatChangeEventHandler(OnPixelFormatChange);

// Force the handler to cancel the operation.
AtalaImage image = new AtalaImage(@"D:\Test Images\1.jpg");
AtalaImage gray = image.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale, null, true);

image.Dispose();
if (gray != null)
    gray.Dispose();


private void OnPixelFormatChange(object sender, PixelFormatChangeEventArgs e)
{
    // Don't allow a 24-bit image to be converted to 8-bit grayscale.
    if (e.CurrentPixelFormat == PixelFormat.Pixel24bppBgr && e.NewPixelFormat == PixelFormat.Pixel8bppGrayscale)
        e.Cancel = true;
}
ChangePixelFormat Example (Visual Basic)
Private  Sub OnPixelFormatChange(ByVal sender As Object, ByVal e As PixelFormatChangeEventArgs) Handles AtalaImage.ChangePixelFormat
    ' Don't allow a 24-bit image to be converted to 8-bit grayscale.
    If e.CurrentPixelFormat = PixelFormat.Pixel24bppBgr And e.NewPixelFormat = PixelFormat.Pixel8bppGrayscale Then
        e.Cancel = True
    End If
End Sub

' Force the handler to cancel the operation.
Dim image As AtalaImage =  New AtalaImage("D:\Test Images\1.jpg") 
Dim gray As AtalaImage =  image.GetChangedPixelFormat(PixelFormat.Pixel8bppGrayscale, Nothing, True) 

image.Dispose()
If Not gray Is Nothing Then
    gray.Dispose()
End If
See Also