AtalaImageChangePixelFormat Event |
Namespace: Atalasoft.Imaging
// 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; }
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