Results 1 to 3 of 3

Thread: [2005] Appending to Image File

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    [2005] Appending to Image File

    I am having problems with the Stream Class and maybe you can help me figure out why this is not work.

    I am storing an image in an image object and trying to append that image to the end of a file already created. And it seems the only way I can do that is will a stream, because of I pass the filename it always overwrites the information.

    I have not worked much with the FileStream and I have trying to read things of msdn but cant seem to find what I am looking for, so if you have any ideas please let me know.

    I am trying to save the image with this method which works if I dont want to append to a file and just overwrite
    VB Code:
    1. Public Sub SaveImage(ByVal Filename As String, ByVal Format As ImageFormat)
    2.         ' No need to do anywork if nothing is set to save.
    3.         If Filename <> String.Empty Or Not (Format Is Nothing) Then
    4.             ' Capture the screen shot using API calls.
    5.             Dim img As Image = Me.CaptureWindow(IUser.GetDesktopWindow())
    6.             Dim size As Size = img.Size
    7.  
    8.             If Not (img Is Nothing) Then
    9.                 ' Do we want to append to a current file?
    10.                 If Me._Append Then
    11.                     Dim fileStream As FileStream = File.OpenRead(Filename)
    12.                  
    13.                     img.Save(fileStream, Format)
    14.                     fileStream.Close()
    15.                 Else
    16.                     ' Overwrite existing images
    17.                     img.Save(Filename, Format)
    18.                 End If
    19.             End If
    20.  
    21.         End If
    22.     End Sub
    Last edited by Jumpercables; Apr 25th, 2006 at 08:15 PM.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2005] Appending to Image File

    Everytime I try to append to the file the actually file gets bigger but only one image appears when I try to open it.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: [2005] Appending to Image File

    If it is an image method you should use appropriate image objects instead, such as the Bitmap object.

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