Android Question i'm getting this error when i press the button

Sadk

Member
B4X:
Sub Button1_Click
    Private b As Bitmap
    b=LoadBitmap(File.DirAssets, "Untikktled.jpg")
    Dim i As Long
    Dim j As Long
    Dim s  As String
   

    s=""

    For i=0 To b.Height
        For j=0 To b.Width
           
            [COLOR=rgb(226, 80, 65)]If b.GetPixel(j,i)=Colors.White Then[/COLOR]
                s=s & "0"
           
            Else
                s=s & "1"
            End If
           
        Next
    Next
   
End Sub




B4X:
Error occurred on line: 69 (Main)
java.lang.IllegalArgumentException: x must be < bitmap.width()
    at android.graphics.Bitmap.checkPixelAccess(Bitmap.java:1960)
    at android.graphics.Bitmap.getPixel(Bitmap.java:1863)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.GetPixel(CanvasWrapper.java:661)
    at b4a.example.main._button1_click(main.java:475)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7300)
    at android.view.View.performClickInternal(View.java:7277)
    at android.view.View.access$3600(View.java:822)
    at android.view.View$PerformClick.run(View.java:28027)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7565)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
 
Solution
BTW, Bitmap.GetPixel is only useful when you want to get the color values of few pixels. Use BitmapCreator to get all values. It will be 1000 times faster.
the error is gone ,but nothing appears in the editbox
1637428145360.jpg

Sadk

Member
BTW, Bitmap.GetPixel is only useful when you want to get the color values of few pixels. Use BitmapCreator to get all values. It will be 1000 times faster.
the error is gone ,but nothing appears in the editbox
1637428145360.jpg
 

Attachments

  • convert image to binary.rar
    27.2 KB · Views: 241
Upvote 0
Solution

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do ?
You need to give more detailed information on:
What do you want to do?
What result do you expect?
etc.
In the code in the first post you try to modify an image, but you do nothing else with it.
Then you speak about an editbox, how is all this related.
Post your test project as zip file, this would be the best way for us to help you.
How to zip a project from within the IDE:

1637485959279.png
 
Upvote 0

Sadk

Member
What exactly do you want to do ?
when you click on the button a massage appears b4a not responding (waiting/ok) , convert the image to binary dose not appear on the edit box
 

Attachments

  • convert image to binary.rar
    27.2 KB · Views: 239
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I still do not understand what you really want to do.
First your layout is not OK, at least for my device, views are out of the screen.
You use the click event of the EditText view, is this what you want to do?
Then you create a string in the converting routine but you do nothing with it.
You need to set this string to the Text property of the EditText view.
Be aware that the number of characters of the string is 255 * 255 = 65025 characters !?
What do you want to do with this.
You compare pixels from the BitmapCreator object "b" but you set the image to bmcRose, why?
In your original project, all pixels in b are transparent.

Attached my test version of your project.
For testing I reduced the loop.
 

Attachments

  • convert image to binary.zip
    13.8 KB · Views: 240
Upvote 0
Top