IsBitonal(Int32,Int32) Method
In This Topic
Determines whether a GdPicture image or the area defined by SetROI() method is composed of black and white pixels only.
This method uses a linear formula to determine the color intent. To obtain more accurate result the ColorDetection() method should be used instead.
This method accepts a threshold parameter which speaks to the confidence of the detection.
Low Threshold values will require high confidence for the image to be determined as bitonal, and high
values will require low confidence for the image to be determined as bitonal.
Syntax
'Declaration
Public Overloads Function IsBitonal( _
ByVal As Integer, _
ByVal As Integer _
) As Boolean
public bool IsBitonal(
int ,
int
)
public function IsBitonal(
: Integer;
: Integer
): Boolean;
public function IsBitonal(
: int,
: int
) : boolean;
public: bool IsBitonal(
int ,
int
)
public:
bool IsBitonal(
int ,
int
)
Parameters
- ImageID
- GdPicture image identifier.
- Threshold
- Threshold between 0 (max confidence) and 765 (min confidence). A value near or
higher than 50 is highly suggested.
Return Value
True if it is a bitonal image, else False.
Example
Finding out if an image is bitonal.
Saving an image to tiff ccitt IV or jpeg depending whether it is bitonal or not.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.bmp");
// Save the image to tiff ccitt iv in case it is bitonal otherwise save to jpeg.
if (gdpictureImaging.IsBitonal(imageID, 0))
{
gdpictureImaging.SaveAsTIFF(imageID, "image.tif", TiffCompression.TiffCompressionCCITT4);
}
else
{
gdpictureImaging.SaveAsJPEG(imageID, "image.jpg", 75);
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Removing staple marks on 1bpp b&w image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.bmp");
if ((gdpictureImaging.GetBitDepth(imageID) == 1) && gdpictureImaging.IsBitonal(imageID, 0))
{
gdpictureImaging.RemoveStapleMark(imageID);
gdpictureImaging.SaveAsTIFF(imageID, "image.tif", TiffCompression.TiffCompressionCCITT4);
}
// Release used resources.
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
Example
Finding out if an image is bitonal.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.bmp");
// Save the image to tiff ccitt iv in case it is bitonal otherwise save to jpeg.
if (gdpictureImaging.IsBitonal(imageID, 0))
{
gdpictureImaging.SaveAsTIFF(imageID, "image.tif", TiffCompression.TiffCompressionCCITT4);
}
else
{
gdpictureImaging.SaveAsJPEG(imageID, "image.jpg", 75);
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.bmp");
if ((gdpictureImaging.GetBitDepth(imageID) == 1) && gdpictureImaging.IsBitonal(imageID, 0))
{
gdpictureImaging.RemoveStapleMark(imageID);
gdpictureImaging.SaveAsTIFF(imageID, "image.tif", TiffCompression.TiffCompressionCCITT4);
}
// Release used resources.
gdpictureImaging.ReleaseGdPictureImage(imageID);
}
See Also