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

Posted on 2008-11-18
Last Modified: 2013-11-26
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 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?
Question by:Joar
    LVL 83

    Expert Comment

    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.

    Author Comment

    It sounds reasonable... How do I resize an image on the fly. Is it some simple function in or...?
    LVL 83

    Accepted Solution

    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


    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
                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)
                    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)
                Return Nothing
            End Try
            Return bmpOut
        End Function

    Open in new window

    LVL 83

    Expert Comment

    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)

    Author Comment

    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!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now