Home > DeveloperSection > Forums > is there any option to save a picturebox to an textfile in vb.net
Madhu Mitha
Madhu Mitha

Total Post:31

Posted on    March-20-2015 11:50 PM

 .NET VB.Net 

 3 Reply(s)
 930  View(s)
Rate this:
Hi thr,,

i want to save my picturebox in a text file.. is there any option to do like tat..

Jennifer Morgan
Jennifer Morgan

Total Post:13

Posted on    March-21-2015 4:58 AM

Hi Madhu,

Could you please explain a bit more about your requirement. As per your current question we are unable to get your requirement.

Madhu Mitha
Madhu Mitha

Total Post:31

Posted on    March-21-2015 5:16 AM

hai jennifer,,

                    I developed a code to display my text in a picturebox using drawstring method.. i have saved that picturebox to an bmp file.. Now i have to convert that bmp file to an .txt file or byte() .. i dono how to convert it.. Can u help me in solving this problem..

thank u in advance..

 my code is..
Public Class Form1
    Dim brush As New Drawing.SolidBrush(Color.Black)
    Dim g2 As System.Drawing.Graphics
    Dim img As New Bitmap(400, 100)
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
               g2 = Graphics.FromImage(img)
        PictureBox1.Image = img
        g2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g2.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
        g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        g2.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Red, 0, 0)
          End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SaveFileDialog1.FileName = ""
        If SaveFileDialog1.ShowDialog <> 1 Then Exit Sub
            Select Case SaveFileDialog1.FilterIndex
                Case 1
                    img.Save(SaveFileDialog1.FileName, ImageFormat.Bmp)
                Case 2
            End Select
            MsgBox("Can not save the LED image!", 48, "LED Saving")
        End Try

    End Sub
End Class

Modified On Mar-21-2015 05:18:31 AM

Pawan Shukla
Pawan Shukla

Total Post:29

Posted on    March-21-2015 8:13 AM

Public Function SetImageComment(input As Image, comment As String) As Image

    Using memStream As New IO.MemoryStream()

        input.Save(memStream, Imaging.ImageFormat.Jpeg)

        memStream.Position = 0

        Dim decoder As New JpegBitmapDecoder(memStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad)

        Dim metadata As BitmapMetadata

        If decoder.Metadata Is Nothing Then

            metadata = New BitmapMetadata("jpg")


            metadata = decoder.Metadata

        End If

        metadata.Comment = comment

        Dim bitmapFrame = decoder.Frames(0)

        Dim encoder As BitmapEncoder = New JpegBitmapEncoder()

        encoder.Frames.Add(bitmapFrame.Create(bitmapFrame, bitmapFrame.Thumbnail, metadata, bitmapFrame.ColorContexts))

        Dim imageStream As New IO.MemoryStream


        imageStream.Position = 0


        input = Nothing

        Return Image.FromStream(imageStream)

    End Using

End Function

Don't want to miss updates? Please click the below button!

Follow MindStick