VB .Net and GDI

Althought i've made this question many times on several newsgroups, i'll do it once more, maybe i get lucky this time.
I've been around this problem for quite long.
So, the situation is this:
I have a picturebox with an image. I use GDI+ to draw lines, points and even other images on top of the first image.
The first image is set on the picturebox throw the following command:

fs = New System.IO.FileStream(PatientDirectory, IO.FileMode.Open)

but the other imagens are inserted throw the following command
Dim srcPic As Graphics = picDraw.CreateGraphics

srcPic.DrawImage(img2, New PointF(rect.X, rect.Y))

So, when i save the image in the picturebox, i only save the first image, the one i inserted throw the first command shown here
fs = New System.IO.FileStream(PatientDirectory, IO.FileMode.Open)

the other images and all GDI graphics, like lines and points, are not saved to the disk

Does anyone knows anything on how to save those lines, points, and new images to disk with the first image?
is there any way to "clip" those things on the main image?

My thanks in advanced

Ricardo Furtado

Comments

  • Hi, i'm not 100% understanding what you want but i'll try :)

    Most likely the problem is that when you draw by using the CreateGraphics method, the data is not actually a part of the picturebox. For example, if you minimize your program then the previous data that was drawn is no longer present. *Unless* you have the code in the Paint event, which will redraw the data.

    To actually make your drawing data a part of the image and make it 'persisted' to the control you should draw the image data and then apply it to the control by using the Picturebox.Image Property.

    Example:

    '
    'A bitmap that will receive the drawing data
    Dim bit As New Bitmap(100, 100)
    '
    'A graphics object which will use the bitmap as a canvas.
    Dim g As Graphics = Graphics.FromImage(bit)
    '
    'A image to add to the drawing data.
    Dim img As Image = Image.FromFile("c:PlayHS.png")
    '
    'Just draw some data on the bitmap.
    g.DrawLine(Pens.Black, 0, 10, 100, 100)
    'And then draw a image.
    g.DrawImage(img, 20, 20)
    '
    'Set the picturebox image to the contents of the bitmap canvas which contains the
    'data that was drawn to it.
    pic.Image = bit
    '
    'Then save the contents of the picturebox image to a file.
    pic.Image.Save("c: estimage.jpg")


    Again, its possible I may not be properly understanding what you want :) But the example above does work and will save the data that was drawn to the image. Hopefully, this will help you :)


    Jason
    --------------------------------------------

    Visual Basic Code Source (New Design!) - http://www.vbcodesource.org

    Visual Basic Code Source - http://www.vbcodesource.com
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion