I tried to find this and have code that should work as far as I can see, but the result in my Crystal Report for some reason is 5 pages instead of 1!
Basically, I have a Crystal report with a full page shot taken with BlobField, which works great when the original image has a width of 2409 pixels and 3436 pixels with a high resolution of 300 dpi.
When I try to use the original image with a width of 1700 by 2436 with a high resolution of 200 dpi, the image height is too large and a little distracting the report to the next page
I thought: “No problem, I just resize the image and the report will display correctly,” but I am having serious difficulties with this. Here is the code that I am currently using, when using the "normal" "Image size and this code, the report displays everything well, but if I need to resize, it stretches to wide and FIFTH pages, which is even worse than leaving it at rest!: (
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length - 1) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
'Byte[] to image
Dim imgMemoryStream = New IO.MemoryStream(Image)
Dim myImage = Drawing.Image.FromStream(imgMemoryStream)
' Check if image is 2409 wide, if it not then resize to 2409 while preserving aspect ratio. WIN.
If myImage.Width <> 2409 Then
MsgBox("myimage before: " & myImage.Width & " by " & myImage.Height)
myImage = ImageResize(myImage, 3436, 2409)
MsgBox("myimage after: " & myImage.Width & " by " & myImage.Height)
Else
MsgBox("myimage (already correct for printing): " & myImage.Width & " by " & myImage.Height)
End If
Dim imgMemoryStream2 As IO.MemoryStream = New IO.MemoryStream()
myImage.Save(imgMemoryStream2, System.Drawing.Imaging.ImageFormat.Jpeg)
Image = imgMemoryStream2.ToArray
objDataRow(strImageField) = Image
, ( , "" BlobField), , . "", , , BlobField .
:
Public Shared Function ImageResize(ByVal image As System.Drawing.Image, _
ByVal height As Int32, ByVal width As Int32) As System.Drawing.Image
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(width, height, image.PixelFormat)
If bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format1bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format4bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format8bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Undefined Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.DontCare Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format16bppArgb1555 Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format16bppGrayScale Then
Throw New NotSupportedException("Pixel format of the image is not supported.")
End If
Dim graphicsImage As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bitmap)
graphicsImage.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
graphicsImage.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphicsImage.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height)
graphicsImage.Dispose()
Return bitmap
End Function
, , Crystal Reports BlobField A4.