B4J Question Canvas/Image "PutPixel"?

wonder

Expert
Licensed User
Longtime User
@Erel, this is a B4J question, I should have posted in the B4J forum.
Please move it accordingly...

----------------------------------------------------------------------------

Is there a Canvas (or Image) "PutPixel" method (using reflection)?

My current workaround is:
B4X:
'in B4J
myCanvas.DrawRect(x, y, 1, 1, color, filled, 0)

I would like to:
B4X:
myCanvas.PutPixel(x, y, color)

'- or -

myImage.PutPixel(x, y, color)
 
Last edited:

wonder

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

wonder

Expert
Licensed User
Longtime User
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
On occasions in some languages that did not have DrawPoint equivalent, I have used DrawLine with a one pixel long line.

I would believe you can package that in a DrawPoint sub wrapper as to keep the same code.

But indeed, it can be worthwhile to open a new thread in B4J.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
You can use getArgb/setArgb.

See this post: https://www.b4x.com/android/forum/t...o-canvas-without-smoothing.42620/#post-257959

Extract from this post:
B4X:
Sub Resample(Input As Image,S As Int) As Image

   Dim W As Double = Input.Width
   Dim H As Double= Input.Height
   Dim SW As Int = Input.Width * S
   Dim SH As Int = Input.Height * S
   
   Dim InputJO,OutputJO,ReaderJO,WriterJO As JavaObject
   OutputJO.InitializeNewInstance("javafx.scene.image.WritableImage",Array As Object(SW,SH))
   InputJO = Input
   
   ReaderJO = InputJO.RunMethod("getPixelReader",Null)
   WriterJO = OutputJO.RunMethod("getPixelWriter",Null)
   
   Dim ARGB As Int
   
   For y = 0 To H-1
     For x = 0 To W -1
       ARGB = ReaderJO.RunMethod("getArgb",Array As Object(x,y))
       For dy = 0 To S - 1
         For dx = 0 To S -1
           WriterJO.RunMethod("setArgb",Array As Object(x * S + dx, y * S + dy,ARGB))
         Next
       Next
     Next
   Next
   
   Return OutputJO
   
End Sub
 
Upvote 0
Top