Android Question Get Bitmap.PixelColor on camera

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello is there way get color of some point on camera wtihout take photo.

i ll draw circle and try make it overlay on cam. i ll try get this object's point Bitmap.PixelColor

is there way ?
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Dear Erel,

I try to do this but I get error in LoadBitmap Error..... I want only get the color of pixel from Preview.


Sub Camera1_Preview (Data() As Byte)
Dim dir As String = File.DirDefaultExternal
camEx.SavePictureToFile(Data, dir, "picture.jpg")

Dim bmp As Bitmap = LoadBitmap(dir, "picture.jpg")
Dim c As Int = bmp.GetPixel(100,100)

Log("Color = " & c)

End Sub
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Ok Erel, I got it!

The example I do based in CCTV and work very well.

Now I need one thing more to complete the App.

You have any sample to convert RGB into COLOR NAME or simply PROXIMITY NAME?

Something like: RGB2NAME ( res(1),res(2),res(3) )

-------------------------------------------------------------------------------------------------------------------------------
Dim jpeg() As Byte = camEx.PreviewImageToJpeg(Data,100)
Dim In As InputStream
In.InitializeFromBytesArray(jpeg, 0, jpeg.Length)

Dim bmp As Bitmap

Try

bmp.Initialize2(In)
In.Close

Dim PixelColor As Int
PixelColor = bmp.GetPixel(bmp.Width/2,bmp.Height/2)

Dim res(4) As Int
res(0) = Bit.UnsignedShiftRight(Bit.AND(PixelColor, 0xff000000), 24)
res(1) = Bit.UnsignedShiftRight(Bit.AND(PixelColor, 0xff0000), 16)
res(2) = Bit.UnsignedShiftRight(Bit.AND(PixelColor, 0xff00), 8)
res(3) = Bit.AND(PixelColor, 0xff)
Log("ARGB = " & res(0) & "," & res(1) & "," & res(2) & "," & res(3))
pnlColor.Color = Colors.RGB(res(1),res(2),res(3))

Catch
End Try


-------------------------------------------------------------------------------------------------------------------------------
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Would be nice if you can implement this as a B4A library or class. Don't want to depend on an online service (no offense).
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hi Bluedude, no offend me, of course!

I implemented this for do quickly nothing more.


the code ion server side is in Classic ASP: take a look: and attachment the table "GlassColor" (i put in xls to better view)

<%@ Language=VBScript %>
<%

Dim strR, strG, strB, strCorName, strSelect

strR = request("R")
strG = request("G")
strB = request("B")

strCorName = ""
strSelect = "select top 1 c.ColorRed, c.ColorBlue, c.ColorGreen, c.ColorName from GlassColor c order by (square(c.ColorRed - " & strR & ") + square(c.ColorGreen - " & strG & ") + square(c.ColorBlue - " & strB & "))"

'*************************************************************************************************************
Dim rs, gConexao
set gConexao = server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
gConexao. open FU_StringConexaoProdutos
rs.CursorLocation = 3 'adUseClient
rs.Open strSelect,gConexao,3,3
if not rs.eof then
strCorName = trim("" & rs("ColorName"))
end if
rs.Close
set rs=nothing
gConexao.Close
set gConexao=nothing

response.write strCorName
response.end

%>



and the call in B4A like this example:

http://www.visualnet.inf.br/servicos/GlassColors.asp?R=255&G=250&B=250


I hope I've helped
 

Attachments

  • GlassColorTable.zip
    28.8 KB · Views: 254
Upvote 0
Top