saving bmp from clipboard to file

S

steve

Hi All

I have a program which takes photos of members using a web cam, then saves
them as bitmap files

The bitmap is used by a Picturebox to display the photo and clicking on a
button enables the camera and another button takes the photo and saves it

In VS 2003(VB) all worked fine, but since moving up to VS 2005 (VB) when I
try to retake a photo and save it I get error messages

'General exception occurred in GDI+' when I try to save the new photo with
the same name as an existing one

I now call ...
picturebox1.dispose
picturebox1 = nothing

before taking the new photo and saving but occasionally get messages that
another process has locked the file when I try to delete the existing file

Has anything changed in VS 2005 ???

Below is the full code for the picture capture routine

Regards
Steve
Private Sub btntakephoto_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btntakephoto.Click

Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()

Dim sql As String = ""

Dim oImgObj As System.Drawing.Image

Try

Clipboard.Clear()

' Copy image to clipboard

SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)

' Get image from clipboard and convert it to a bitmap

If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then

If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then

oImgObj = oDataObj.GetData(DataFormats.Bitmap, True)

'To Save as Bitmap

If My.Computer.FileSystem.FileExists(photopath & Me.Tag & ".bmp") Then

My.Computer.FileSystem.DeleteFile(photopath & Me.Tag & ".bmp")

End If

oImgObj.Save(photopath & Me.Tag & ".bmp",
System.Drawing.Imaging.ImageFormat.Bmp)

ClosePreviewWindow()
 
P

Peter Huang [MSFT]

Hi

Based on my understanding, you get the exception when the code line
"Image.Save" is executed.
If I have any understanding, please feel free to post here.

Can you post the detailed callstack and error message when the exception
occur?

Also have you tried to save to another name when you retake the photo, did
the problem persists?

From your description, the problem may be relieved if you all
picturebox1.dispose and picturebox1 = nothing, but from your code snippet,
it did not tell us how do you associate the image with the picturebox1. I
just guess it is possible that the picturebox1 is locking the image
file(just an idea).

Can you explain your code logic thoroughlly?

Also you may try to call the GC.Collect after you are trying to dispose the
picturebox1 and set it to null.

Thanks for your efforts!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi

Just want to say Hi, and I was wondering how everything is going.
If anything is unclear, please let me know.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top