Android Question Can I find the only empty distance in the picture

AlfaizDev

Well-Known Member
Licensed User
Hello
Here's a simple example.
I have imageView1 on it.
And another tool label1 has writing
Can I find the only empty distance in the image and put label1 on top of it?
I heard about something called the picture chart, through which you can access every part of the picture.

Do any of you have any idea about this?
and thanks
2.png
 

TILogistic

Expert
Licensed User
Longtime User
see post:
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
for space use patern "\s{2,}" (2 or more spaces)

sample with text:
B4X:
    Dim Text As String = "Hello Hello Hello            Hello"
    Log(Text)
    Text = Regex.Replace("\s{2,}", Text, " [THIS WAS ADDED] ")
    Log(Text)

1645683020914.png
 
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
for space use patern "\s{2,}" (2 or more spaces)

sample with text:
B4X:
    Dim Text As String = "Hello Hello Hello            Hello"
    Log(Text)
    Text = Regex.Replace("\s{2,}", Text, " [THIS WAS ADDED] ")
    Log(Text)

View attachment 126019
Thanks, but I want to find the void in a picture, not in a text.
As I explained in the question
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1645693120066.png


This will help you get started:
B4X:
Private Sub FindLargestGapAtTheCenter (bc As BitmapCreator) As B4XRect
    Dim y As Int = bc.mHeight / 2
    Dim MaxGapStart As Int
    Dim MaxGapEnd As Int
    Dim GapStart As Int
    Dim white As ARGBColor
    white = bc.ColorToARGB(xui.Color_White, white)
    Dim argb As ARGBColor
    Dim InsideAGap As Boolean
    For x = 0 To bc.mWidth - 1 Step 2 'step is an optimization factor
        bc.GetARGB(x, y, argb)
        If argb.r = white.r And argb.b = white.b And argb.g = white.g Then
            If InsideAGap = False Then
                GapStart = x
                InsideAGap = True
            End If
        Else
            If InsideAGap Then
                If x-1 - GapStart > MaxGapEnd - MaxGapStart Then
                    MaxGapEnd = x - 1
                    MaxGapStart = GapStart
                End If
                InsideAGap = False
            End If
        End If
    Next
    Dim r As B4XRect
    r.Initialize(MaxGapStart, y, MaxGapEnd, y)
    Return r
End Sub

B4J project is attached.
 

Attachments

  • Project.zip
    13 KB · Views: 108
Upvote 0

AlfaizDev

Well-Known Member
Licensed User
View attachment 126027

This will help you get started:
B4X:
Private Sub FindLargestGapAtTheCenter (bc As BitmapCreator) As B4XRect
    Dim y As Int = bc.mHeight / 2
    Dim MaxGapStart As Int
    Dim MaxGapEnd As Int
    Dim GapStart As Int
    Dim white As ARGBColor
    white = bc.ColorToARGB(xui.Color_White, white)
    Dim argb As ARGBColor
    Dim InsideAGap As Boolean
    For x = 0 To bc.mWidth - 1 Step 2 'step is an optimization factor
        bc.GetARGB(x, y, argb)
        If argb.r = white.r And argb.b = white.b And argb.g = white.g Then
            If InsideAGap = False Then
                GapStart = x
                InsideAGap = True
            End If
        Else
            If InsideAGap Then
                If x-1 - GapStart > MaxGapEnd - MaxGapStart Then
                    MaxGapEnd = x - 1
                    MaxGapStart = GapStart
                End If
                InsideAGap = False
            End If
        End If
    Next
    Dim r As B4XRect
    r.Initialize(MaxGapStart, y, MaxGapEnd, y)
    Return r
End Sub

B4J project is attached.
Thank you
He works well
Is there a last modification so that there are 2 empty space or more
Thank you
 
Upvote 0
Top