| |

VerySource

 Forgot password?
 Register
Search
View: 969|Reply: 7

Help me see, image processing problems

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-7 18:40:01
| Show all posts |Read mode
I would like to ask the following program to achieve a real-time error 28, stack space by clicking all the points in the picture frame on the right with a mouse click on any blue area in the picture frame on the left. "Overflow" error? Thank you all. code show as below:

VERSION 5.00
Begin VB.Form Form1
   Caption = "Form1"
   ClientHeight = 6285
   ClientLeft = 60
   ClientTop = 450
   ClientWidth = 9000
   LinkTopic = "Form1"
   ScaleHeight = 6285
   ScaleWidth = 9000
   StartUpPosition = 3 'Window default
   WindowState = 2 'Maximized
   Begin VB.PictureBox pic2
      AutoRedraw = -1 'True
      AutoSize = -1 'True
      Height = 2295
      Left = 5640
      ScaleHeight = 149
      ScaleMode = 3 'Pixel
      ScaleWidth = 173
      TabIndex = 1
      Top = 120
      Width = 2655
   End
   Begin VB.PictureBox pic1
      AutoRedraw = -1 'True
      AutoSize = -1 'True
      Height = 4830
      Left = 120
      Picture = "Form1.frx": 0000
      ScaleHeight = 318
      ScaleMode = 3 'Pixel
      ScaleWidth = 356
      TabIndex = 0
      Top = 120
      Width = 5400
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Type BITMAP '14 bytes
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Private Declare Function GetObject Lib "gdi32" Alias ​​"GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Dim picBits () As Byte
Dim picInfoD As BITMAP 'Load the information used in the processed image
Dim BytesperPixel As Integer

'get bitmap info
Private Function GetBI (pic As PictureBox, picBits () As Byte)
    Dim i As Long
    
    With pic
        GetObject .Image, Len (picInfoD), picInfoD
        BytesperPixel = picInfoD.bmBitsPixel\8
        ReDim picBits (1 To picInfoD.bmWidth * picInfoD.bmHeight * BytesperPixel)
        
        GetBitmapBits .Image, UBound (picBits), picBits (1)
    End With
End Function

'Invert the image that is continuous with the clicked point on the image
Private Function SSMO (x As Single, y As Single, c As Integer)
    'On Error Resume Next
    
    If picBits ((y * picInfoD.bmWidth + x) * BytesperPixel + c) = 255 Then
        picBits ((y * picInfoD.bmWidth + x) * BytesperPixel + c) = 0
        picBits ((y * picInfoD.bmWidth + x) * BytesperPixel + 3-c) = 255
        DoEvents
        If picBits (((y-1) * picInfoD.bmWidth + x-1) * BytesperPixel + c) = 255 Then
            SSMO x-1, y-1, c
        End If
        If picBits (((y-1) * picInfoD.bmWidth + x) * BytesperPixel + c) = 255 Then
            SSMO x, y-1, c
        End If
        If picBits (((y-1) * picInfoD.bmWidth + x + 1) * BytesperPixel + c) = 255 Then
            SSMO x + 1, y-1, c
        End If
        If picBits ((y * picInfoD.bmWidth + x-1) * BytesperPixel + c) = 255 Then
            SSMO x-1, y, c
        End If
        If picBits ((y * picInfoD.bmWidth + x + 1) * BytesperPixel + c) = 255 Then
            SSMO x + 1, y, c
        End If
        If picBits (((y + 1) * picInfoD.bmWidth + x-1) * BytesperPixel + c) = 255 Then
            SSMO x-1, y + 1, c
        End If
        If picBits (((y + 1) * picInfoD.bmWidth + x) * BytesperPixel + c) = 255 Then
            SSMO x, y + 1, c
        End If
        If picBits (((y + 1) * picInfoD.bmWidth + x + 1) * BytesperPixel + c) = 255 Then
            SSMO x + 1, y + 1, c
        End If
    End If
    Exit Function
End Function

Private Sub Form_Load ()
    pic2.Width = pic1.Width
    pic2.Height = pic1.Height
    GetBI pic1, picBits ()
End Sub

Private Sub pic1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
    SSMO x, y, 1
    SetBitmapBits pic2.Image, UBound (picBits), picBits (1)
End Sub
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-16 11:00:01
| Show all posts
You must first check the error code, and then analyze the value of the variable in combination with the context, or add an msgbox statement to the code to show the value of the variable. Stack errors are usually caused by your variables being used too much or the variable type is too small. Question, you can define the variable as Long or Double type to try
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-16 11:15:01
| Show all posts
Also note that sometimes the unit used in VB is different from the pixel, it is twips, 1 pixel = 15 twips
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-16 12:45:02
| Show all posts
Find the wrong place and prescribe the right medicine.
Reply

Use magic Report

0

Threads

16

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-28 15:00:01
| Show all posts
This is simple, you can get the answer by searching online.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 14:15:02
| Show all posts
Did you write gdi32 yourself
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 14:30:02
| Show all posts
Don't understand, Bangding
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-2 14:45:01
| Show all posts
Don't understand, Bangding
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list