Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15033

VS 2010 [RESOLVED] A Generic Error Occurred In GDI+

$
0
0
Hi

Hope you all are doing great.


I am trying to do a comparison between to image files for some specific Pixl values. I have been successful in it however it runs in the first go ( first go: -that is uploading the image for the first time) and when i upload another image and try to run it again my code gives me an error " A Generic Error Occurred In GDI+".

below mention is my code.


Code:

Option Compare Binary
Option Explicit On
Option Infer On
Option Strict On
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.IO

Public Class Form13
    Dim add As String
    Dim BitmapO As Bitmap
    Public Structure PixelStr
        Public ColorO As Color  'Defines the pixel's color.
        Public X As Integer    'Defines the pixel's horizontal position.
        Public Y As Integer    'Defines the pixel's vertical position.
    End Structure


    Public Sub Main()
        Dim Pixels As New List(Of PixelStr)
        Dim pix1c1, pix1c2, pix1c3, pix2c1, pix2c2, pix2c3, A1, A2, A3 As Integer
        Dim q As Integer
        Dim files_image(BitmapO.Height * BitmapO.Width, 4) As Integer
        For x As Integer = 0 To BitmapO.Width - 1
            For y As Integer = 0 To BitmapO.Height - 1
                Pixels.Add(New PixelStr With {.ColorO = BitmapO.GetPixel(x, y), .x = x, .y = y})
            Next y
        Next x
        Using FileO As New System.IO.StreamWriter("D:\Codinates_circle.txt")
            For Each Pixel As PixelStr In Pixels
                With Pixel
                    files_image(q, 0) = .X
                    files_image(q, 1) = .Y
                    files_image(q, 2) = .ColorO.R
                    files_image(q, 3) = .ColorO.G
                    files_image(q, 4) = .ColorO.B
                    q = q + 1
                End With
            Next Pixel
        End Using

        Using Filet As New System.IO.StreamWriter("D:\Codinates_circle4.txt")
            For j As Integer = 0 To BitmapO.Height * BitmapO.Width
                If j < BitmapO.Height * BitmapO.Width - 50 Then
                    pix1c1 = files_image(j, 2)
                    pix1c2 = files_image(j, 3)
                    pix1c3 = files_image(j, 4)

                    End If

                If pix1c1 = 183 or pix1c1=197 Then
                    BitmapO.SetPixel(files_image(j, 0), files_image(j, 1), Color.DarkRed)
                    Filet.WriteLine("{0};{1}", files_image(j, 0), files_image(j, 1))
              End If
            Next
        End Using
        Try
            BitmapO.Save("D:\maw243.jpg")
        Catch ex As Exception
            MsgBox("Sorry ! We ran into an error.")
        End Try
        AI_Theme_Form4.Show()
        AI_Theme_Form4.PictureBox2.BackgroundImage = Image.FromFile("D:\maw243.jpg")
        AI_Theme_Form4.PictureBox2.BackgroundImageLayout = ImageLayout.Stretch
        BitmapO.Dispose()
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        OpenFileDialog1.ShowDialog()
        add = OpenFileDialog1.FileName
        Try
            PictureBox1.BackgroundImage = Image.FromFile(add)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        BitmapO = New Bitmap(add)
    End Sub


I have tried to put everything in the code - it works but only in the first time execution but when i run it again it does not work "A Generic Error Occured in GDI+"

Viewing all articles
Browse latest Browse all 15033

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>