Results 1 to 1 of 1

Thread: Generic Error in GDI+ While Saving An Image

  1. #1

    Thread Starter
    Join Date
    Jan 2021

    Question Generic Error in GDI+ While Saving An Image


    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.
    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
            End Using
            Catch ex As Exception
                MsgBox("Sorry ! We ran into an error.")
            End Try
            AI_Theme_Form4.PictureBox2.BackgroundImage = Image.FromFile("D:\maw243.jpg")
            AI_Theme_Form4.PictureBox2.BackgroundImageLayout = ImageLayout.Stretch
        End Sub
        Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
            add = OpenFileDialog1.FileName
                PictureBox1.BackgroundImage = Image.FromFile(add)
            Catch ex As Exception
            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+"
    Last edited by si_the_geek; Jan 13th, 2021 at 12:56 PM. Reason: added Code tags
    < / L R. . . . >

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