Results 1 to 2 of 2

Thread: [2.0] Image Header

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    66

    [2.0] Image Header

    I have a picture loaded into a picturebox. How would I write a header (My custom header) + the picture binary into another file?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Image Header

    You would create a file stream, convert your header text to a byte array and write it to the stream. You'd then read the binary data of the Image and write it to the same file. I haven't tested it but something like this should work:
    Code:
    using (System.IO.FileStream stream = new System.IO.FileStream("file path here"))
    {
        byte[] header = System.Text.Encoding.ASCII.GetBytes("header text here");
    
        stream.Write(header, 0, header.GetUpperBound(0));
        this.pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
        stream.Close();
    }
    Edit: It may be a better idea to write some specifically formatted binary data as the header rather than text, but you get the idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width