Dim caption As String = "Example: GetPageImageMaskMode"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim oGdPictureImaging As GdPictureImaging = New GdPictureImaging()
Dim status As GdPictureStatus = gdpicturePDF.SelectPage(1)
If status = GdPictureStatus.OK Then
Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim imageID As Integer = 0, bitDepth As Integer = 0
Dim maskMode As PdfImageMaskType = PdfImageMaskType.PdfMaskTypeUnknown
Dim cs As PdfColorSpace = PdfColorSpace.PdfColorSpaceUnknown
Dim mask As Boolean = False
For i As Integer = 0 To imageCount - 1
imageID = gdpicturePDF.ExtractPageImage(i+1)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
mask = False
bitDepth = oGdPictureImaging.GetBitDepth(imageID)
status = oGdPictureImaging.GetStat()
If status = GdPictureStatus.OK Then
If bitDepth <> 1 Then
status = oGdPictureImaging.FxGrayscale(imageID)
Else
cs = gdpicturePDF.GetPageImageColorSpace(i)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
If cs <> PdfColorSpace.PdfColorSpaceDeviceGray Then
status = oGdPictureImaging.ConvertTo1Bpp(imageID)
End If
End If
If status = GdPictureStatus.OK Then
maskMode = gdpicturePDF.GetPageImageMaskMode(i)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
mask = ((maskMode <> PdfImageMaskType.PdfMaskTypeNone) AndAlso (maskMode <> PdfImageMaskType.PdfMaskTypeUnknown))
End If
End If
End If
If status = GdPictureStatus.OK Then
status = gdpicturePDF.ReplaceImage(gdpicturePDF.GetPageImageResName(i), imageID, mask)
End If
End If
oGdPictureImaging.ReleaseGdPictureImage(imageID)
If status <> GdPictureStatus.OK Then
MessageBox.Show("Finding image properties or replacing the image has failed with the status: " + status.ToString(), caption)
Exit For
End If
Else
MessageBox.Show("The ExtractPageImage() method has failed with the status: " + status.ToString(), caption)
Exit For
End If
Next
If imageCount > 0 Then
If status = GdPictureStatus.OK Then
status = gdpicturePDF.SaveToFile("test_updated.pdf", True)
If status = GdPictureStatus.OK Then
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
Else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption)
End If
End If
Else
MessageBox.Show("The first page does not contain any image. The document has not been saved.", caption)
End If
Else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption)
End If
oGdPictureImaging.Dispose()
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageMaskMode";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
GdPictureStatus status = gdpicturePDF.SelectPage(1);
if (status == GdPictureStatus.OK)
{
int imageCount = gdpicturePDF.GetPageImageCount();
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
int imageID = 0, bitDepth = 0;
PdfImageMaskType maskMode = PdfImageMaskType.PdfMaskTypeUnknown;
PdfColorSpace cs = PdfColorSpace.PdfColorSpaceUnknown;
bool mask = false;
for (int i = 0; i < imageCount; i++)
{
imageID = gdpicturePDF.ExtractPageImage(i+1);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
mask = false;
bitDepth = oGdPictureImaging.GetBitDepth(imageID);
status = oGdPictureImaging.GetStat();
if (status == GdPictureStatus.OK)
{
if (bitDepth != 1)
{
status = oGdPictureImaging.FxGrayscale(imageID);
}
else
{
cs = gdpicturePDF.GetPageImageColorSpace(i);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
if (cs != PdfColorSpace.PdfColorSpaceDeviceGray)
{
status = oGdPictureImaging.ConvertTo1Bpp(imageID);
}
}
if (status == GdPictureStatus.OK)
{
maskMode = gdpicturePDF.GetPageImageMaskMode(i);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
mask = ((maskMode != PdfImageMaskType.PdfMaskTypeNone) && (maskMode != PdfImageMaskType.PdfMaskTypeUnknown));
}
}
}
if (status == GdPictureStatus.OK)
{
status = gdpicturePDF.ReplaceImage(gdpicturePDF.GetPageImageResName(i), imageID, mask);
}
}
oGdPictureImaging.ReleaseGdPictureImage(imageID);
if (status != GdPictureStatus.OK)
{
MessageBox.Show("Finding image properties or replacing the image has failed with the status: " + status.ToString(), caption);
break;
}
}
else
{
MessageBox.Show("The ExtractPageImage() method has failed with the status: " + status.ToString(), caption);
break;
}
}
if (imageCount > 0)
{
if (status == GdPictureStatus.OK)
{
status = gdpicturePDF.SaveToFile("test_updated.pdf", true);
if (status == GdPictureStatus.OK)
MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
else
MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption);
}
}
else
MessageBox.Show("The first page does not contain any image. The document has not been saved.", caption);
}
else
MessageBox.Show("The GetPageImageCount() method has failed with the status: " + status.ToString(), caption);
}
else
MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption);
oGdPictureImaging.Dispose();
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();