Code to create a simple color picker based on an image:
Two canvases are used. The first one reads the color from the image and the second one draws the selection circle.
You can replace the image with any other image to change the color palete.
File is available here: https://www.b4x.com/android/forum/attachments/colorpicker-zip.56334/
Two canvases are used. The first one reads the color from the image and the second one draws the selection circle.
You can replace the image with any other image to change the color palete.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
cvsColors.Initialize(pnlColors)
cvsOverlay.Initialize(pnlOverlay)
End Sub
Sub pnlColors_Touch (Action As Int, X As Float, Y As Float)
Dim cx = pnlColors.Width / 2, cy = pnlColors.Height / 2 As Float
If Sqrt(Power(x - cx, 2) + Power(y - cy, 2)) > pnlColors.Width / 2 Then Return
Dim clr As Int = cvsColors.Bitmap.GetPixel(X, Y) '<---- clr is the result
Activity.Color = clr
cvsOverlay.DrawColor(Colors.Transparent)
cvsOverlay.DrawCircle(X, Y, 20dip, Colors.Black, False, 3dip)
pnlOverlay.Invalidate
End Sub
File is available here: https://www.b4x.com/android/forum/attachments/colorpicker-zip.56334/