[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-18
5
Medium Priority
?
198 Views
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 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
Comment
Question by:Joar
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22992760
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
 

Author Comment

by:Joar
ID: 22997490
It sounds reasonable... How do I resize an image on the fly. Is it some simple function in vb.net or...?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 23002358
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 23002368
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
 

Author Comment

by:Joar
ID: 23013743
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

830 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