---
title: "how to save a shape as bmp file"  
description: "how to save a shape as bmp file"  
author: "Madhu Mitha"  
published: 2015-03-27  
updated: 2015-03-30  
canonical: https://www.mindstick.com/forum/23059/how-to-save-a-shape-as-bmp-file  
category: ".net"  
tags: ["vb.net"]  
reading_time: 3 minutes  

---

# how to save a shape as bmp file

hi thr...\
I want to save three shape[rectangle] as a single bmp file.. is there [option to save](https://www.mindstick.com/forum/23037/is-there-any-option-to-save-a-picturebox-to-an-textfile-in-vb-dot-net) it..**my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) is**\

```
Public Class Form1    Dim bmp As New Bitmap(Me.Width, Me.Height)    Private Sub PaintTheForm()        Dim bmp As New Bitmap(Me.Width, Me.Height)        Using g As Graphics = Graphics.FromImage(bmp)            Dim blackPen As New Pen(Color.Black, 1)            'to draw first rectangle rectangle            Dim rect As New Rectangle(0, 0, 30, 16)            g.DrawRectangle(Pens.Black, rect)            'to draw second rectangle            Dim rect1 As New Rectangle(30, 0, 114, 8)            g.DrawRectangle(Pens.Black, rect1)            'to draw thrid rectangle            Dim rect2 As New Rectangle(30, 8, 114, 8)            g.DrawRectangle(Pens.Black, rect2)            ' To type text            Dim big_font As New Font("Comic Sans MS", 12, FontStyle.Bold, GraphicsUnit.Pixel)            g.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixel            g.DrawString("helo", big_font, Brushes.Black, 0, 0)            g.Dispose()            ' End Sub            Me.BackgroundImage = bmp        End Using    End Sub    Private Sub btnPaint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaint.Click        PaintTheForm()    End Sub    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click        SaveFileDialog1.FileName = ""        If SaveFileDialog1.ShowDialog <> 1 Then Exit Sub        Try            Select Case SaveFileDialog1.FilterIndex                Case 1                    bmp.Save(SaveFileDialog1.FileName, Imaging.ImageFormat.Bmp)                Case 2            End Select        Catch            MsgBox("Can not save the LED image!", 48, "LED Saving")        End Try    End SubEnd Class
```

\
when I [tried to save](https://answers.mindstick.com/qa/45247/what-do-you-think-of-sacking-of-dr-kafeel-who-tried-to-save-children-in-gorakhpur-by-buying-oxygen-himself) this I could not save the three rectangle box... so can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) help in solving my [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic)\
\
thanks\

## Replies

### Reply by Anonymous User

Hi madhu

Try this code:

If you want to save the image that is displayed in the picture box, complete with any lines that may have been drawn on top of it during run-time, you can use the Control.DrawToBitmap method

Here's an example of a complete solution. First, the user is prompted by a save dialog (entitled "Save Image" and filtering to bitmap images (*.bmp) by default). If they click OK, the image displayed in the picture box is drawn to a temporary bitmap, and that temporary bitmap is saved to the location they specified. If they click Cancel, the file is not saved and the method simply exits.

```
private void Save_Click(object sender, EventArgs e){    //Show a save dialog to allow the user to specify where to save the image file    using (SaveFileDialog dlgSave = new SaveFileDialog())    {        dlgSave.Title = "Save Image";        dlgSave.Filter = "Bitmap Images (*.bmp)|*.bmp|All Files (*.*)|*.*";        if (dlgSave.ShowDialog(this) == DialogResult.OK)        {            //If user clicked OK, then save the image into the specified file            using (Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height))            {                picturebox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));                bmp.Save(dlgSave.FileName);            }        }    }}
```


---

Original Source: https://www.mindstick.com/forum/23059/how-to-save-a-shape-as-bmp-file

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
