IS THERE ANY OPTION TO SAVE A PICTUREBOX TO AN TEXTFILE IN VB.NET

Madhu Mitha

Total Post:31

Points:217
Posted by  Madhu Mitha
VB.Net 
 999  View(s)
Ratings:
Rate this:
Hi thr,,


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

    Post:13

    Points:95
    Re: is there any option to save a picturebox to an textfile in vb.net

    Hi Madhu,


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

  1. Madhu Mitha

    Post:31

    Points:217
    Re: is there any option to save a picturebox to an textfile in vb.net

    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
            Try
                Select Case SaveFileDialog1.FilterIndex
                    Case 1
                        img.Save(SaveFileDialog1.FileName, ImageFormat.Bmp)
                    Case 2
                End Select
            Catch
                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
  1. Pawan Shukla

    Post:29

    Points:203
    Re: is there any option to save a picturebox to an textfile in vb.net

    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")

            Else

                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

            encoder.Save(imageStream)

            imageStream.Position = 0

            input.Dispose()

            input = Nothing

            Return Image.FromStream(imageStream)

        End Using

    End Function

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!