vb Code:
  1. Private Sub saveImage(ByVal fileName As String, ByVal format As Drawing.Imaging.ImageFormat, ByVal pb As PictureBox)
  2.     Dim img As New Bitmap(DirectCast(pb.Image.Clone, Bitmap), pb.image.Width, pb.image.Height)
  3.     Dim gr As Graphics = Graphics.FromImage(img)
  4.  
  5.     Dim sf As New StringFormat
  6.     sf.Alignment = StringAlignment.Near
  7.     sf.LineAlignment = StringAlignment.Center
  8.  
  9.     For Each lbl As Label In pb.Controls.OfType(Of Label)()
  10.         gr.FillRectangle(New SolidBrush(lbl.BackColor), lbl.Bounds)
  11.         gr.DrawString(lbl.Text, lbl.Font, New SolidBrush(lbl.ForeColor), lbl.Bounds, sf)
  12.         'this draws a red border
  13.         gr.DrawRectangle(Pens.Red, lbl.Bounds)
  14.     Next
  15.  
  16.     img.Save(fileName, format)
  17.  
  18. End Sub