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?
JoarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.