Hi,
I'm developing a test report using PDFSharp and VB.Net, everything is working like charm but now I'm facing a problem that I'm unable to resolve. This test I'm developing is the first stage to deploy PDFSharp as a reporting tool in my company so I have to make some basic functionality for a faster report designing in the future.
This is the function I'm having problem with
Code:
Private Function imagenRedimensionar(ByVal foto As String, ByVal imgImagen As XImage, ByVal intAltoLimite As Integer, ByVal intAnchoLimite As Integer) As String
Dim strLogoRedimensionado As String = ""
Dim strExtension As String
Dim bmImagen As Bitmap
Dim intAltoRedimensionado, intAnchoRedimensionado, intContador As Integer
Try
'Change the path to the picture so I can save and load the resized one from there.
strExtension = foto.Substring(foto.IndexOf(CType(".", Char)), foto.Length - foto.IndexOf(CType(".", Char)))
strLogoRedimensionado = foto.Substring(0, foto.IndexOf(CType(".", Char))) + "_redimensionado" + strExtension
'Load the original image
bmImagen = New Bitmap(foto)
'Get the original heith and with of the picture
intAltoRedimensionado = imgImagen.PointHeight
intAnchoRedimensionado = imgImagen.PointWidth
'If one of the properties is bigger than the rectangle is going to fit make it smaller
'in both sides until de biggest one fits.
While intAltoRedimensionado > intAltoLimite Or intAnchoRedimensionado > intAnchoLimite
intAltoRedimensionado = CType(intAltoRedimensionado * 0.95, Integer)
intAnchoRedimensionado = CType(intAnchoRedimensionado * 0.95, Integer)
End While
Dim bmImagenRedimensionada As New Bitmap(bmImagen, intAnchoRedimensionado, intAltoRedimensionado)
intContador = 0
'If the file exist it must be in the header of gooter and won't let me save it
While System.IO.File.Exists(strLogoRedimensionado)
'So I change the name again (Stupid, change code to use the last resized image if it fits)
strLogoRedimensionado = foto.Substring(0, foto.IndexOf(CType(".", Char))) + "_redimensionado" + intContador.ToString + strExtension
intContador += 1
End While
'Save the resized picture to the new path
bmImagenRedimensionada.Save(strLogoRedimensionado)
Catch ex As Exception
strLogoRedimensionado = foto
End Try
'Return the new path so the resized image can be loaded from there
Return strLogoRedimensionado
End Function
The code runs smoothly and without any errors, but when the new picture is created I'm giving the new heith and width in points instead of pixels, thus the picture displayed is always smaller than it should be
Code:
Dim bmImagenRedimensionada As New Bitmap(bmImagen, intAnchoRedimensionado, intAltoRedimensionado)
I would like to know if I can convert the points to pixels or if I can acomplish this in any other way. I also would like not to use MigraDoc since all this code is going to end up in a server and I would only use for this.
Thank you very much,
Iker