How i can convert an selected image in corelDraw to an BW Grayscale image ?
I have try this code, but it not works.
private void Button_Click_1(object sender, RoutedEventArgs e)
Image testImage = (Image)corelApp.ActiveSelection.ConvertToBitmap(24, true, true, true, 500, corel.cdrAntiAliasingType.cdrNormalAntiAliasing, true, false, false, 95);
//void ConvertToBW(cdrRenderType RenderType, int Intensity = 100, int Threshold = 128, cdrHalftoneType Halftone = cdrHalftoneSquare, int HalftoneAngle = 45, int HalftoneSize = 0);
First, I would use ConvertToBitmapEx. Second, it return a Shape not an Image. So something like this:
corel.Shape testImage = corelApp.ActiveSelection.ConvertToBitmapEx(corel.cdrImageType.cdrGrayscaleImage, true, true, 500, corel.cdrAntiAliasingType.cdrNormalAntiAliasing, true, false, 95);
Your solution works greatBut i would also to try this mode. (ConvertToBW) So i get an error....
private void Button_Click(object sender, RoutedEventArgs e)
corel.Shape testImage = corelApp.ActiveSelection.Bitmap.ConvertToBW(corel.cdrRenderType.cdrRenderFloyd, 100, 128, corel.cdrHalftoneType.cdrHalftoneSquare, 45, 0);
You have a couple of issues. Since you are selecting every shape you could have a shape that is not a bitmap and that would crash things. You should also to the convert on the shape and not the selection.
Here is a quick example. This gets the first shape in the selection and then checks if it is a bitmap. If it is a bitmap then it does the ConvertToBW.
corel.Shape s = corelApp.ActiveSelectionRange.FirstShape;
if (s.Type == corel.cdrShapeType.cdrBitmapShape)
s.Bitmap.ConvertToBW(corel.cdrRenderType.cdrRenderFloyd, 100, 128, corel.cdrHalftoneType.cdrHalftoneSquare, 45, 0);
Many thanks, this works great.