user1433452
user1433452

Reputation: 21

Colouring in a picture using overlays or filled polygons

I am trying to create a VB.net form application to visually fill in a floor plan with different colours according to reservation status.

The basic floor plan is white and the idea is to colour in the various apartments in different colours depending on some variables.

I have tried overlaying .png pictures on top of each other but this doesn't work due to the non-true nature of transparency in visual studio as soon as you overlay more than 2 PNGs.

Not much more success with drawing polygons either

Here is what I would like to achieve and I'd be grateful for some help or suggestions:

enter image description here

Upvotes: 1

Views: 947

Answers (1)

LarsTech
LarsTech

Reputation: 81620

Try drawing on top of the image with a brush that has an alpha value:

Protected Overrides Sub OnPaint(e As PaintEventArgs)
  e.Graphics.DrawImage(backImage, New Point(0, 0))

  Dim room As New List(Of Point)
  room.Add(New Point(45, 48))
  room.Add(New Point(165, 48))
  room.Add(New Point(190, 75))
  room.Add(New Point(190, 234))
  room.Add(New Point(150, 234))
  room.Add(New Point(150, 245))
  room.Add(New Point(45, 245))

  Using br As New SolidBrush(Color.FromArgb(100, Color.Blue))
    e.Graphics.FillPolygon(br, room.ToArray())
  End Using
  Using p As New Pen(Color.Blue, 3)
    e.Graphics.DrawPolygon(p, room.ToArray())
  End Using

  MyBase.OnPaint(e)
End Sub

Result:

enter image description here

Upvotes: 3

Related Questions