Results 1 to 9 of 9

Thread: Saving an Image in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3

    Question Saving an Image in vb.net

    Hi,

    I'm trying to save an image from a picturebox which contains a live webcam feed using the following line in a button,

    pictureBox1.image.Save("data.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

    but when I run this, I keep getting an error saying "Object reference not set to an instance of an object"..how can I can fix this problem??

    Thx,

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I don't understand how you are actually able to run a webcam video through a picturebox, but by the looks of that error..

    the picturebox does not actually contain the image data... so when you try to save the contents of its image property as you did above, there is nothing there, so it reports no object available.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    In other words, you are probably implementing the webcam video by drawing on picturebox's graphics surface, which does not mean the picturebox contains the image. It simply means you are overriding what the picturebox would normally draw on its surface (the image contained in its image property).

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3
    so can I get a hold of the webcam data from the picturebox??

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Do you have the code you use to put the webcam data there?

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    just a suggestion, I dont have any idea whatsoever on what's going on... but as nemaroller said the picturebox.Image is probably null.... if you are drawing the stuff on the picturebox manually then I guess this would apply to you:
    instead of using the graphics object passed in the paint event of the picturebox (of instead of calling picturebox.CreateGraphics) try to do something like this
    VB Code:
    1. dim gr as graphics = graphics.fromImage (yourPictureBox.Image)
    2. 'now when you call 'gr' it modifies the actual image in the picturebox

    dunno if I'm helping, but thought I should mention it
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3
    I followed a tutorial from the following site to implement the live web cam feed..

    http://www.webtropy.com/articles/art7.asp

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ok, that code is what i suspected.

    The image data does not reside inside the picturebox image property. The code is simply drawing on the picturebox's graphics surface. The picturebox isn't drawing the image, the VFW (Video For Windows) API is, therefore the picturebox knows nothing about what's being displayed.

    There is no way to 'capture' the image using Picturebox methods.

    However I suspect the VFW API may have a way to snapshot the image data, and fill a byte array or buffer with it.

  9. #9
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316
    I don't know if you're interested in third party tools but...

    I use an activeX add-in that I purchased from http://www.activevideotools.com for under a hundred bucks that made the task of capturing still photos from an incoming video feed extremely easy.

    Im using a winnov videum capture card but any video card that supports VFW will work.
    SCUZ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width