Solved

How to do get system.drawing.graphics content into a picture box?

Posted on 2011-02-24
1
433 Views
Last Modified: 2012-05-11
I have created a functin that scales an image.

The scaling appears to go ok, but the problem is that I have no idea how to get the scaled graphic (gt_dest) back into the picturebox (picBannerBox) that is on Form1.

How do I do that?
Private Function ScaleImage(ByVal imgTemp As Image, ByVal box As PictureBox) As Graphics
        Dim fSize As String
        Dim iNewx As Integer = 0
        Dim iNewy As Integer = 0

        Dim oldBMP As New Bitmap(CInt(imgTemp.Width), CInt(imgTemp.Height))

        'Determine which side is larger than the canvas, 

        If ImageTooWide(imgTemp) And ImageTooTall(imgTemp) Then
            '...and if both are larger, pick the larger side.
            If imgTemp.Height > imgTemp.Width Then
                fSize = "height"
            Else
                fSize = "width"
            End If
        Else
            '... Other wise pick the one that is larger.
            If ImageTooWide(imgTemp) Then fSize = "width"
            If ImageTooTall(imgTemp) Then fSize = "height"
        End If

        Select Case fSize
            Case "width"
                iNewx = picBannerBox.Width
                iNewy = iNewx / imgTemp.Width * imgTemp.Height
            Case "height"
                iNewy = picBannerBox.Height
                iNewx = iNewy / imgTemp.Height * imgTemp.Width
        End Select
        Dim newBMP As New Bitmap(iNewx, iNewy)
        'Create a blank, new graphic that is the correct *new* size
        Dim gt_dest As Graphics = Graphics.FromImage(newBMP)
        'Draw our picture onto it, scaling it...
        gt_dest.DrawImage(imgTemp, 0, 0, iNewx + 1, iNewy + 1)
        'Draw new image to picBannerBox
        '????????????
    End Function

Open in new window

0
Comment
Question by:DrDamnit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 32

Accepted Solution

by:
DrDamnit earned 0 total points
ID: 34974327
Figured it out:

Dim newBMP As New Bitmap(iNewx, iNewy)
        Dim newImage As Image
        newImage = CType(newBMP, Image)

        'Create a blank, new graphic that is the correct *new* size
        Dim gt_dest As Graphics = Graphics.FromImage(newImage)
        'Draw our picture onto it, scaling it...
        gt_dest.DrawImage(imgTemp, 0, 0, iNewx + 1, iNewy + 1)
        Return newImage

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net 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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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