Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
Casalechi

Graphics usando memoria até bugar

Question

 o codigo esta em um timer com interval de "1000"  é um reconhecimento de img mas quando  dentro de um timer ele consome muita memoria até dar erro!
preciso de uma ajuda para otimizar, preciso esvaziar a memoria quando o codigo chega ao fim ou coisa do tipo tentei varias coisa mais nada funcionou o desafio foi lançado! help me plx

 

Try
            Dim bmpSource2 As Bitmap = New Bitmap("C:\Users\USER\Pictures\ox\others\efeito.bmp")
            Dim bmpScreen2 As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Dim clrScreen, clrUL, clrUR, clrLL, clrLR As Color
            'capture screen

            Using g As Graphics = Graphics.FromImage(bmpScreen2)
                g.CopyFromScreen(0, 0, 0, 0, bmpScreen2.Size)
            End Using


            clrUL = bmpSource2.GetPixel(0, 0)
            clrUR = bmpSource2.GetPixel(bmpSource2.Width - 1, 0)
            clrLL = bmpSource2.GetPixel(0, bmpSource2.Height - 1)
            clrLR = bmpSource2.GetPixel(bmpSource2.Width - 1, bmpSource2.Height - 1)


            For x = 1000 To 1100
                For y = 300 To 350
                    clrScreen = bmpScreen2.GetPixel(x, y)
                    If clrScreen = clrUL Then
                        'found the upperleft pixel check upper right
                        clrScreen = bmpScreen2.GetPixel(x + bmpSource2.Width - 1, y)
                        If clrScreen = clrUR Then
                            clrScreen = bmpScreen2.GetPixel(x, y + bmpSource2.Height - 1)
                            If clrScreen = clrLL Then
                                clrScreen = bmpScreen2.GetPixel(x + bmpSource2.Width - 1, y + bmpSource2.Height - 1)
                                If clrScreen = clrLR Then
                                    'Se achar
                                    varial = varial  + 1

                                End If
                            End If
                        End If
                    End If
                Next
            Next
        Catch ex As ArgumentException
            MsgBox("deu ruim")
            Exit Sub
        End Try
    End Sub

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

O tempo do Timer ( 1 segundo ) está sendo  insuficiente para que a interação do For X e o For Y cheguem ao final. 

outra coisa é que voce esta dimensionando a sua matriz a cada segundo ( isso só vai consumindo memória )

sugestões:

1 - aumente o tempo do Timer ou desative o Timer no começo da rotina e ative novamente ao finalizar a interação do For

2 - apague a matriz e redimensione novamente dentro do Timer

Erase (SeuArray)
Redim (SeuArray)

3 - execute essa rotina em um ThRead ( rodar em segundo plano )

abraço

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148393
    • Total Posts
      643786
×
×
  • Create New...