Solved

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

Posted on 2011-02-24
1
431 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL and CLR parameter strings 9 66
How do i create a simple array in a public class? 6 38
Adding Rows to Grid 4 34
CSS styling problem 3 28
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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