Filling image with color

xamrex

New Member
Hello.
How can I fill this bulb:
9083041200_1342940683.jpg

with a color?

My phone will be conected with microcontroller, and this bulb should shows color form RGB Diode.

How can I fill this bulb with color?
 

klaus

Expert
Licensed User
Longtime User
I don't think that there does exist a library for doing this.
It would be easier to load bitmaps with colored bulbs.
Or you could write your own routine.
If you want to fill a surface this one must have only one color.
Your bitmap seems not beeing 'clean' inside.

Best regards.
 
Upvote 0

xamrex

New Member
It would be easier to load bitmaps with colored bulbs.
It is not possible. I would have to have 255*255*255 bitmaps;/

Your bitmap seems not beeing 'clean' inside.
I can clean this bitmap inside...


I thought about circle filled inside with color, but this circle does not look like a bulb;/
 
Upvote 0

magicuser68

Member
Licensed User
Longtime User
You could use Photoshop or Gimp and make the part you want to fill with color transparent then save it in ".png" format? In your program create a panel and add your light bulb bitmap. To change the color of the bulb just change your background color of the panel.

FYI - Transparency is sometimes called alpha channel.


Update:
I edited your picture and added the alpha channel. I have attached it for you.

- Scott
 

Attachments

  • lightbulb.png
    lightbulb.png
    20.8 KB · Views: 544
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here you have an example of drawing with a Path. It would also need a bitmap with the bulb image and the internal part transparent like migicuser68s' proposal.
But migicuser68s' solution is simpler than mine.
But I post it anyway as an example.
B4X:
Sub Process_Globals
    Dim Timer1 As Timer
End Sub

Sub Globals
    Dim pnlMain As Panel
    Dim cvsMain As Canvas
    Dim pthBulb As Path
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlMain.Initialize("pnlMain")
    Activity.AddView(pnlMain, 50%x - 100dip, 50dip, 200dip, 300dip)
    pnlMain.Color = Colors.White
    
    cvsMain.Initialize(pnlMain)
    cvsMain.RemoveClip
    Timer1.Initialize("Timer1", 1000)
    Timer1.Enabled = True
End Sub

Sub Activity_Resume
    DefineBulbPath
    DrawBulb(Colors.Red)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Timer1.Enabled = False
End Sub

Sub Timer1_Tick
    DrawBulb(Colors.RGB(Rnd(0,256), Rnd(0,256), Rnd(0,256)))
    pnlMain.Invalidate
End Sub

Sub DrawBulb(col As Int)
    cvsMain.DrawPath(pthBulb, col, True, 1)
End Sub

Sub DefineBulbPath
    Dim x0, y0 As Float
    
    x0 = pnlMain.Width / 2
    y0 = 20dip
    pthBulb.Initialize(x0, y0)
    pthBulb.LineTo(x0 + 20dip, y0 + 5dip)
    pthBulb.LineTo(x0 + 40dip, y0 + 10dip)
    pthBulb.LineTo(x0 + 60dip, y0 + 30dip)
    pthBulb.LineTo(x0 + 70dip, y0 + 50dip)
    pthBulb.LineTo(x0 + 70dip, y0 + 80dip)
    pthBulb.LineTo(x0 + 65dip, y0 + 100dip)
    pthBulb.LineTo(x0 + 55dip, y0 + 120dip)
    pthBulb.LineTo(x0 + 45dip, y0 + 150dip)
    pthBulb.LineTo(x0 + 40dip, y0 + 180dip)
    pthBulb.LineTo(x0 + 38dip, y0 + 186dip)
    pthBulb.LineTo(x0 + 32dip, y0 + 190dip)

    pthBulb.LineTo(x0 - 32dip, y0 + 190dip)
    pthBulb.LineTo(x0 - 38dip, y0 + 186dip)
    pthBulb.LineTo(x0 - 40dip, y0 + 180dip)
    pthBulb.LineTo(x0 - 45dip, y0 + 150dip)
    pthBulb.LineTo(x0 - 55dip, y0 + 120dip)
    pthBulb.LineTo(x0 - 65dip, y0 + 100dip)
    pthBulb.LineTo(x0 - 70dip, y0 + 80dip)
    pthBulb.LineTo(x0 - 70dip, y0 + 50dip)
    pthBulb.LineTo(x0 - 60dip, y0 + 30dip)
    pthBulb.LineTo(x0 - 40dip, y0 + 10dip)
    pthBulb.LineTo(x0 - 20dip, y0 + 5dip)
    pthBulb.LineTo(x0, y0)
End Sub
Best regards.
 

Attachments

  • FillBulb.zip
    5.6 KB · Views: 184
  • FillBulb.jpg
    FillBulb.jpg
    17.6 KB · Views: 206
Last edited:
Upvote 0
Top