Ir ao conteúdo
  • Cadastre-se

Visual Basic VB6 - como evitar 1 erro na criação de DIB's?


Posts recomendados

eu tenho 1 classe em VB6 para criar DIB's:

Private Function AlignScan(ByVal inWidth As Long, ByVal inDepth As Integer) As Long
    AlignScan = (((inWidth * inDepth) + &H1F) And Not &H1F&) \ &H8
End Function

Public Function NewImage(ByVal ImageWidth As Long, ByVal ImageHeight As Long, Optional color As ColorConstants = vbBlack) As Long
    If (Width > 0 Or Height > 0 Or hBitmap > 0 Or PointerPixelData > 0) Then DeleteImage
    Width = ImageWidth
    Height = ImageHeight

    'Criar HDC
   
    MemoryHDC = CreateCompatibleDC(0)

    With bmiInfo.bmiHeader
        .biSize = Len(bmiInfo.bmiHeader)
        .biWidth = Width
        .biHeight = -Height ' is negative for start on top left pixel image
        .biPlanes = 1
        .biBitCount = 32
        .biCompression = BI_RGB
        .biSizeImage = AlignScan(bmiInfo.bmiHeader.biWidth, bmiInfo.bmiHeader.biBitCount) * bmiInfo.bmiHeader.biHeight
    End With
    If MemoryHDC = 0 Then MsgBox "error: HDC not created!!!"
    hBitmap = CreateDIBSection(0&, bmiInfo, DIB_RGB_COLORS, PointerPixelData, 0&, 0&)
    If hBitmap = 0 Then MsgBox "error: " & GetLastError()
    oldBitmap = SelectObject(MemoryHDC, hBitmap)
    
    'using pointers:
     ' Get the bits in the from DIB section:
    
    With tSA
        .fFeatures = FADF_FIXEDSIZE Or FADF_AUTO
        .cbElements = 4
        .cDims = 1
        .Bounds(0).lLbound = 0
        .Bounds(0).cElements = bmiInfo.bmiHeader.biHeight * bmiInfo.bmiHeader.biWidth
        .pvData = PointerPixelData
    End With
     'Erase bDib
    ' Make the bDib() array point to the memory addresses:
    CopyMemory ByVal VarPtrArray(bDib()), VarPtr(tSA), 4
    CopyMemory ByVal VarPtrArray(bDibBGRA()), VarPtr(tSA), 4
    'Clear color
End Function
'e como limpar:
Public Sub DeleteImage()
    'Clear pointer:
    Dim z As Long
    CopyMemory ByVal VarPtrArray(bDib), VarPtr(z), 4
    Erase bDib
    
    Dim s As Long
    CopyMemory ByVal VarPtrArray(bDibBGRA), VarPtr(z), 4
    Erase bDibBGRA


    SelectObject MemoryHDC, OldBrush
    DeleteObject NewBrush


    SelectObject MemoryHDC, OldPen
    DeleteObject NewPen


    SelectObject MemoryHDC, oldBitmap
    DeleteObject hBitmap
    

    'ReleaseDC 0, MemoryHDC
    DeleteDC MemoryHDC
    
End Sub

o meu problema é: após 4 execuções no IDE(mas não acontece no EXE), eu obtenho 1 erro nesta linha:
 

Public Function NewImage(ByVal ImageWidth As Long, ByVal ImageHeight As Long, Optional color As ColorConstants = vbBlack) As Long
    If (Width > 0 Or Height > 0 Or hBitmap > 0 Or PointerPixelData > 0) Then DeleteImage
    Width = ImageWidth
    Height = ImageHeight

    'Criar HDC
   
    MemoryHDC = CreateCompatibleDC(0)

    With bmiInfo.bmiHeader
        .biSize = Len(bmiInfo.bmiHeader)
        .biWidth = Width
        .biHeight = -Height ' is negative for start on top left pixel image
        .biPlanes = 1
        .biBitCount = 32
        .biCompression = BI_RGB
        .biSizeImage = AlignScan(bmiInfo.bmiHeader.biWidth, bmiInfo.bmiHeader.biBitCount) * bmiInfo.bmiHeader.biHeight
    End With
    If MemoryHDC = 0 Then MsgBox "error: HDC not created!!!"
    hBitmap = CreateDIBSection(0&, bmiInfo, DIB_RGB_COLORS, PointerPixelData, 0&, 0&)
    If hBitmap = 0 Then MsgBox "error: " & GetLastError() 'ERRO: não cria o DIB...

erro 8: "ERROR_NOT_ENOUGH_MEMORY 8 (0x8) Not enough memory resources are available to process this command." https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
porquê este erro? porque só aparece após executar 4 vezes no IDE e não no EXE?
para voltar a executar, eu tenho de  terminar\fechar o IDE e voltar a executar... estranho este erro 😞

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!