How to draw pineapple ring and output it as bitmap

Danny 20 Reputation points
2025-11-24T17:49:27.3533333+00:00

This is pineapple ring I wanted to draw using VB code:

pineapple ring

Imagine the background color is black. Each segment must be same size. The line color can be same for practice purpose. The final image have to output to bitmap file.

For those who have no idea how pineapple ring looks like, here is the image as reference:

pineapple ring 2

Developer technologies | VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 3,725 Reputation points Microsoft External Staff
    2025-11-25T12:18:31.87+00:00

    Thank you for reaching out.

    The code draws onto a Bitmap using a Graphics object:

    • Create a blank bitmap (600×600)
    • Draw two circles (outer + inner) centered on the image
    • Divide the ring into 8 equal slices By drawing 8 lines spaced 45° apart
    • Apply colors to the divider lines Cycling through Yellow → Pink → Blue
    • Save the finished bitmap to the user’s Desktop (pineapple_ring_step6.bmp)

    Angles are calculated in radians:

    angle = i * (Math.PI / 4)

    This guarantees every slice is exactly the same size.

    pineapple_ring.txt
    Output screenshot
    User's image

    Please let us know if you require any further assistance, we’re happy to help.

    If you found this information useful, kindly mark this as "Accept Answer".


  2. Danny 20 Reputation points
    2025-11-25T16:40:20.23+00:00

    Here is the sample output screenshot:

    pineapple ring 3

    The code I was using:

    `Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint`
    

    'NOTE: add PictureBox control to winform and set its background color to darkgreen

    'PictureBox1.BackColor = Color.DarkGreen

    Dim x_value As Int32

    Dim y_value As Int32

    x_value = 50

    y_value = 50

    Dim x_value_b As Int32

    Dim y_value_b As Int32

    x_value_b = 100

    y_value_b = 100

    Dim pieBounds As New Rectangle(x_value, y_value, 200, 200)

    ' Define the start angle and sweep angle in degrees

    Dim startAngle As Single = 0

    Dim sweepAngle As Single = 360

    Dim count As Int32

    Dim degree As Single

    Dim pen_a As New Pen(Color.Black) 'this pen is used for drawing the outer ring

    degree = -7 'set the first segment's degree position

    For count = 1 To 8 'divide 360 degree to 8 segments

    degree = degree + 45 'each segment has 45 degree

    pen_a.Dispose() 'destroy previous instance

    pen_a = New Pen(Color.Blue) 'can change color for each segment, if desire

    e.Graphics.DrawPie(pen_a, pieBounds, degree, 45)

    Next

    'now we draw the inner ring

    Dim pieBounds_b As New Rectangle(x_value_b, y_value_b, 100, 100)

    Dim brush_b As New SolidBrush(Color.DarkGreen)

    'draw the circle (fill in color)

    e.Graphics.FillPie(brush_b, pieBounds_b, startAngle, sweepAngle)

    brush_b.Dispose()

    'draw the circle outline

    Dim pen_d As New Pen(Color.Black)

    e.Graphics.DrawEllipse(pen_d, pieBounds_b)

    pen_d.Dispose()

    End Sub


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.