• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

How do I dynamically load images that have to be resized in a local report in Visual Studio 2005

My app is going to print documents for all may clients in one run. The print is created by a local report (rdlc) in the vb.net app (Visual Studio 2005).  The datasource is a procedure getting data from the db.
My problem: The clients have stored some images (that is a logo and a scanned signature) which I shall output on the printed documents. Different images for different clients. A path to the images does the job, BUT each image needs to be rezized to a fixed area on the document. And I cannot see any possibility to specify the resizing parameters to the images at run time. I am able to do report modifying before starting the report, by modifying the XML definition, but not at runtime. The modifcation parameters will be different for each clients document (page).
Any ideas?
0
Joar
Asked:
Joar
  • 3
  • 2
1 Solution
 
CodeCruiserCommented:
Why dont you resize the source images? If you are able to dynamically change the path of image file then you could load an original image, resize it and store it in temp file, then point to that temp file in the report.
0
 
JoarAuthor Commented:
It sounds reasonable... How do I resize an image on the fly. Is it some simple function in vb.net or...?
0
 
CodeCruiserCommented:
Yes. It is very simple.
To start with, you would need a dummyfunction which is passed as a parameter to the thumbnailing process. I use the following

    Public Function DummyCallBack() As Boolean
        Return False
    End Function

then

Dim cb As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf DummyCallBack)

and finally the attached function code would return you a resized image of the desired size.
    Public Function CreateThumbnail(ByVal lcFilename As String, ByVal lnWidth As Integer, ByVal lnHeight As Integer) As Drawing.Bitmap
        Dim bmpOut As System.Drawing.Image = Nothing
 
        Try
            Dim loBMP As Drawing.Image = Image.FromFile(lcFilename) 'New Drawing.Image(lcFilename)
            Dim loFormat As Drawing.Imaging.ImageFormat = loBMP.RawFormat
            Dim lnRatio As Decimal
            Dim lnNewWidth As Integer = 0
            Dim lnNewHeight As Integer = 0
 
            If (loBMP.Width < lnWidth And loBMP.Height < lnHeight) Then
                Return loBMP
            End If
 
            If (loBMP.Width > loBMP.Height) Then
                lnRatio = CType(lnWidth / loBMP.Width, Decimal)
                lnNewWidth = lnWidth
                Dim lnTemp As Decimal = loBMP.Height * lnRatio
                lnNewHeight = CType(lnTemp, Integer)
            Else
                lnRatio = CType(lnHeight / loBMP.Height, Decimal)
                lnNewHeight = lnHeight
                Dim lnTemp As Decimal = loBMP.Width * lnRatio
                lnNewWidth = CType(lnTemp, Integer)
            End If
            bmpOut = New Bitmap(lnNewWidth, lnNewHeight)
            Dim g As Graphics = Graphics.FromImage(bmpOut)
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight)
            g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight)
            loBMP.Dispose()
        Catch
            Return Nothing
        End Try
        Return bmpOut
    End Function

Open in new window

0
 
CodeCruiserCommented:
Forget about the call back. You dont need it with this function. You could use that callback with a simpler but not as good thumbnailing process. That process is to create a thumbnail size image of an existing image using the following

dim img as image = bimg.GetThumbnailImage(115, 86, cb, IntPtr.Zero)
0
 
JoarAuthor Commented:
Sorry, I have been busy and now I am leaving for the weekend.
Next I will look at your code and do some testing.
Thank you so far!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now