Results 1 to 2 of 2

Thread: System.Runtime.InteropServices.ExternalException generic error in GDI+ help wanted.

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    15

    System.Runtime.InteropServices.ExternalException generic error in GDI+ help wanted.

    Hi ALL,

    In trying to answer the post by forum member makko in this thread.>>

    http://www.vbforums.com/showthread.p...89#post3265789

    I have the following code be I keep get the above EXCEPTION, would low hard-drive disc space cause this problem?

    Would I need to add images in the PAINT event as well, if so how?
    I am trying to use the

    My.Computer.FileSystem.SpecialDirectories.Temp

    directory too as I feel adding an image is a singular event, it does not need to happen continuously.

    Any help for makko and I would be much appreciated. :-)

    Code:
    Public Class Form1
    
    Friend WithEvents PictureBox1 As New PictureBox
    Friend WithEvents btnAdd As New Button
    Friend WithEvents btnSave As New Button
    Friend WithEvents ofd As New OpenFileDialog
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    Me.WindowState = FormWindowState.Maximized
    PictureBox1.Location = New Point(5, 50)
    PictureBox1.Size = New Size(2110, 600)
    Me.Controls.Add(PictureBox1)
    btnAdd.Location = New Point(5, 5)
    btnAdd.Size = New Size(150, 30)
    btnAdd.Text = "Add Image"
    Me.Controls.Add(btnAdd)
    btnSave.Location = New Point(btnAdd.Width + 25, 5)
    btnSave.Size = New Size(150, 30)
    btnSave.Text = "Save Picture"
    Me.Controls.Add(btnSave)
    
    Dim newBitmap As System.Drawing.Bitmap = New Bitmap(2110, 600, Imaging.PixelFormat.Format32bppRgb)
    Dim g As System.Drawing.Graphics = Graphics.FromImage(newBitmap)
    g.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, 2110, 600))
    
    Dim myPath As String = My.Computer.FileSystem.SpecialDirectories.MyPictures
    ofd.InitialDirectory = myPath
    ofd.Filter = "Jpeg files|*.jpg;*.jpeg|Bitmap files|*.bmp|PNG files|*.png|All picture files|*.jpg;*.jpeg;*.bmp;*.png"
    
    'newBitmap.Save(myPath & "/aaa.jpg")
    'PictureBox1.Image = Image.FromFile(myPath & "/aaa.jpg")
    
    End Sub
    
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    
    
    
    End Sub
    
    Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    
    Static imageWidth As Integer
    Dim img As Image
    Try
    ofd.ShowDialog()
    img = Image.FromFile(ofd.FileName)
    PictureBox1.CreateGraphics.DrawImage(img, imageWidth, 0)
    'Save to the temporary folder.>>
    img.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "/tempImage.jpg")
    'Retrieve the temporary image.>>
    PictureBox1.Image = Image.FromFile(My.Computer.FileSystem.SpecialDirectories.Temp & "/tempImage.jpg")
    imageWidth += img.Width
    Catch ex As Exception
    MessageBox.Show(ex.ToString)
    End Try
    
    End Sub
    
    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    
    Dim sfd As New SaveFileDialog
    Try
    sfd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyPictures
    sfd.Filter = "Jpeg files|*.jpg;*.jpeg|Bitmap files|*.bmp|PNG files|*.png|All picture files|*.jpg;*.jpeg;*.bmp;*.png"
    sfd.ShowDialog()
    Dim img As Image
    img = PictureBox1.Image
    Me.Text = sfd.FileName
    img.Save(sfd.FileName)
    Catch ex As Exception
    MessageBox.Show(ex.ToString)
    End Try
    
    End Sub
    End Class



    Regards,

    John
    Last edited by j-a-oliver; Jun 24th, 2008 at 08:26 AM.

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