2 Replies - 10646 Views - Last Post: 08 February 2010 - 03:46 PM Rate Topic: -----

#1 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

read image from file and then overwrite the file.

Posted 06 February 2010 - 06:55 AM

Hi.
i have this simple code for reading image from file
        pic = Application.StartupPath & "\medlem" & "\" & txtp.Text & ".jpg"
        Dim myimage As New Bitmap(pic)
        Try
            If File.Exists(pic) = True Then

                PictureBox1.Image = myimage
            ElseIf File.Exists(pic) = False Then
                ' PictureBox1.Image = My.Resources.siluett3
            End If
        Catch ex As Exception
            MsgBox(ex)
        End Try


but i cant the user to be able to overwrite the file.
but i cant. because my program is using the file.

here is the code for the event the is going to overwrite the file
Try


                If Formspara.ShowDialog = DialogResult.Yes Then
                    
                    If File.Exists(SAVE_PATH & "\" & Form1.txtp.Text & ".jpg") = True Then
                        Response = MessageBox.Show("The file '" & fso.GetName(Form1.txtp.Text & ".jpg").ToLower & "' already exist in the destination folder '" & _
                                                       SAVE_PATH & "'" & vbCrLf & vbCrLf & "Do you want to overwite it?", Text, MessageBoxButtons.YesNo, _
                                                                  MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
                        'If Response = Windows.Forms.DialogResult.Yes Then
                        '    Form1.pic = Application.StartupPath & "\medlem\laddar.jpg"
                        '    File.Delete(SAVE_PATH & "\" & Form1.txtp.Text & ".jpg")
                        '    bmap.Save(SAVE_PATH & "\" & Form1.txtp.Text & ".jpg")
                        'End If
                        If Response = Windows.Forms.DialogResult.No Then Exit Sub
                    End If
                End If

            Catch ex As Exception
                MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try
            Try

                bmap.Save(SAVE_PATH & "\" & Form1.txtp.Text & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If


the new image comes from the computers web camera.


the only thing i cant get to work is how to overwrite the file.

anyone that knows how to do?

thanks in advance :)

This post has been edited by EndLessMind: 07 February 2010 - 04:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: read image from file and then overwrite the file.

#2 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: read image from file and then overwrite the file.

Posted 07 February 2010 - 03:57 AM

i got it to work one time..
there is the code for the event that loads the picture
Private Sub TextBox11_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtp.TextChanged
        pic = Application.StartupPath & "\medlem" & "\" & txtp.Text & ".jpg"
        Try
            If File.Exists(pic) = True Then
                Dim myimage As New System.Drawing.Bitmap(pic)
                PictureBox1.Image = myimage
            ElseIf File.Exists(pic) = False Then
                PictureBox1.Image = My.Resources.siluett3
            End If
        Catch ex As Exception
            MsgBox(ex)
        End Try
    End Sub


and here is the code that should make the program stop using the file and then overwrite it
 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        Dim s As String = Form1.txtp.Text
        Form1.txtp.Text = "laddar"
        Dim data As IDataObject
        Dim SAVE_PATH As String = Application.StartupPath & "\medlem"
        Dim FileDialog As New Formspara
        Dim fso = My.Computer.FileSystem
        Form1.pic = Application.StartupPath & "\Images"
        SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
        data = Clipboard.GetDataObject()
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
            picCapture.Image = bmap
            ClosePreviewWindow()
            MenuItem1.Enabled = False
            MenuItem3.Enabled = False
            MenuItem2.Enabled = True
            If Formspara.ShowDialog = DialogResult.Yes Then
                bmap.Save(SAVE_PATH & "\" & s & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)   
                Form1.txtp.Text = s
            End If
        End If
    End Sub


as i said.. it work´t ones.
but now i get "A general error occurred in GDI+"
Was This Post Helpful? 0
  • +
  • -

#3 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 194
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: read image from file and then overwrite the file.

Posted 08 February 2010 - 03:46 PM

anyone? plz?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1