GetPageImageResolution Method (GdPicturePDF)
In This Topic
Returns the vertical and the horizontal resolution (DPI) of an image, specified by its index within the currently selected page of the loaded PDF document.
Syntax
'Declaration
Public Function GetPageImageResolution( _
ByVal As Integer, _
ByRef As Single, _
ByRef As Single _
) As GdPictureStatus
public GdPictureStatus GetPageImageResolution(
int ,
ref float ,
ref float
)
public function GetPageImageResolution(
: Integer;
var : Single;
var : Single
): GdPictureStatus;
public function GetPageImageResolution(
: int,
: float,
: float
) : GdPictureStatus;
public: GdPictureStatus GetPageImageResolution(
int ,
ref float ,
ref float
)
public:
GdPictureStatus GetPageImageResolution(
int ,
float% ,
float%
)
Parameters
- ImageIdx
- The 0-based index of the image within the current page. It must be a value from 0 to GdPicturePDF.GetPageImageCount-1.
- HorizontalResolution
- Output parameter. The horizontal resolution (DPI) of the specified image.
- VerticalResolution
- Output parameter. The vertical resolution (DPI) of the specified image.
Return Value
A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
We strongly recommend always checking this status first.
Example
How to find out the resolution (both horizontal and vertical) of all images contained within the PDF document.
Dim caption As String = "Example: GetPageImageResolution"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim message As String = ""
Dim pageCount As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
For i As Integer = 1 To pageCount
If gdpicturePDF.SelectPage(i) = GdPictureStatus.OK Then
message = message + "Page nr." + i.ToString() + ":" + vbCrLf
Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
Dim hRes As Single = 0, vRes As Single = 0
For j As Integer = 0 To imageCount - 1
status = gdpicturePDF.GetPageImageResolution(j, hRes, vRes)
If status = GdPictureStatus.OK Then
message = message + "The image indexed as " + j.ToString() + " has the following resolution: horizontal = " + hRes.ToString() + ", vertical = " + vRes.ToString() + "." + vbCrLf
Else
message = message + "The GetPageImageResolution() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Next
Else
If status = GdPictureStatus.OK Then
message = message + "This page doesn't contain any image." + vbCrLf
Else
message = message + "The GetPageImageCount() method has failed with the status: " + status.ToString() + vbCrLf
End If
End If
Else
message = message + "The SelectPage() method has failed for the page nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
End If
Next
MessageBox.Show(message, caption)
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("This file doesn't contain any page.", caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageResolution";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
string message = "";
int pageCount = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (pageCount > 0))
{
for (int i = 1; i <= pageCount; i++)
{
if (gdpicturePDF.SelectPage(i) == GdPictureStatus.OK)
{
message = message + "Page nr." + i.ToString() + ":\n";
int imageCount = gdpicturePDF.GetPageImageCount();
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (imageCount > 0))
{
float hRes = 0, vRes = 0;
for (int j = 0; j < imageCount; j++)
{
status = gdpicturePDF.GetPageImageResolution(j, ref hRes, ref vRes);
if (status == GdPictureStatus.OK)
message = message + "The image indexed as " + j.ToString() + " has the following resolution: horizontal = " + hRes.ToString() + ", vertical = " + vRes.ToString() + ".\n";
else
message = message + "The GetPageImageResolution() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + "\n";
}
}
else
{
if (status == GdPictureStatus.OK)
message = message + "This page doesn't contain any image.\n";
else
message = message + "The GetPageImageCount() method has failed with the status: " + status.ToString() + "\n";
}
}
else
{
message = message + "The SelectPage() method has failed for the page nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
}
}
MessageBox.Show(message, caption);
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("This file doesn't contain any page.", caption);
else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
Example
How to find out the resolution (both horizontal and vertical) of all images contained within the PDF document.
Dim caption As String = "Example: GetPageImageResolution"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
Dim message As String = ""
Dim pageCount As Integer = gdpicturePDF.GetPageCount()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
For i As Integer = 1 To pageCount
If gdpicturePDF.SelectPage(i) = GdPictureStatus.OK Then
message = message + "Page nr." + i.ToString() + ":" + vbCrLf
Dim imageCount As Integer = gdpicturePDF.GetPageImageCount()
status = gdpicturePDF.GetStat()
If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
Dim hRes As Single = 0, vRes As Single = 0
For j As Integer = 0 To imageCount - 1
status = gdpicturePDF.GetPageImageResolution(j, hRes, vRes)
If status = GdPictureStatus.OK Then
message = message + "The image indexed as " + j.ToString() + " has the following resolution: horizontal = " + hRes.ToString() + ", vertical = " + vRes.ToString() + "." + vbCrLf
Else
message = message + "The GetPageImageResolution() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + vbCrLf
End If
Next
Else
If status = GdPictureStatus.OK Then
message = message + "This page doesn't contain any image." + vbCrLf
Else
message = message + "The GetPageImageCount() method has failed with the status: " + status.ToString() + vbCrLf
End If
End If
Else
message = message + "The SelectPage() method has failed for the page nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
End If
Next
MessageBox.Show(message, caption)
Else
If status = GdPictureStatus.OK Then
MessageBox.Show("This file doesn't contain any page.", caption)
Else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
End If
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageResolution";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
string message = "";
int pageCount = gdpicturePDF.GetPageCount();
GdPictureStatus status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (pageCount > 0))
{
for (int i = 1; i <= pageCount; i++)
{
if (gdpicturePDF.SelectPage(i) == GdPictureStatus.OK)
{
message = message + "Page nr." + i.ToString() + ":\n";
int imageCount = gdpicturePDF.GetPageImageCount();
status = gdpicturePDF.GetStat();
if ((status == GdPictureStatus.OK) && (imageCount > 0))
{
float hRes = 0, vRes = 0;
for (int j = 0; j < imageCount; j++)
{
status = gdpicturePDF.GetPageImageResolution(j, ref hRes, ref vRes);
if (status == GdPictureStatus.OK)
message = message + "The image indexed as " + j.ToString() + " has the following resolution: horizontal = " + hRes.ToString() + ", vertical = " + vRes.ToString() + ".\n";
else
message = message + "The GetPageImageResolution() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + "\n";
}
}
else
{
if (status == GdPictureStatus.OK)
message = message + "This page doesn't contain any image.\n";
else
message = message + "The GetPageImageCount() method has failed with the status: " + status.ToString() + "\n";
}
}
else
{
message = message + "The SelectPage() method has failed for the page nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
}
}
MessageBox.Show(message, caption);
}
else
{
if (status == GdPictureStatus.OK)
MessageBox.Show("This file doesn't contain any page.", caption);
else
MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
}
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also