Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: TJPEGImage.SaveToStream problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    TJPEGImage.SaveToStream problem

    if I set DIBNeeded won't that make the jpeg the same size as a bitmap when I save it to stream? The reason I'm using jpeg is to make the stream as small as possible.

    my method still isn't working, If I put some data in the stream before the jpeg I get a jpeg error #53 when I try to read the jpeg even though it's now in the right position. Anyone know what #53 is?

    Peter

  2. #2

    TJPEGImage.SaveToStream problem

    When saving,
    AStream.Seek(8, LStart);
    should be
    AStream.Seek(8, soFromCurrent);
    Edit: Error 53 is "File Not Found", check msdn for error codes

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    TJPEGImage.SaveToStream problem

    What I have done is the following:

    [pascal]procedure TForm1.Button1Click(Sender: TObject);
    Var
    F : TFileStream;
    M,M2 : TMemoryStream;
    J,J1 : TJPEGImage;
    X,Y,Z : Integer;
    begin
    J := TJPEGImage.Create;
    J.LoadFromFile('C:\cairnsgames\letter.jpg'); // Load an Image
    X := 100;
    M := TMemoryStream.Create;
    M2 := TMemoryStream.Create;
    M.Write(X,SizeOf(Integer)); // Write Tag Information
    J.SaveToStream(M2);
    X := M2.Size; // Calculate the size of the JPEG
    M2.Free;
    M.Write(X,SizeOf(Integer)); // Write Size
    J.SaveToStream(M); // Write Image
    J1 := TJPEGImage.Create; // Create a New Image
    M.Seek(0,soBeginning); // Move to start of stream
    M.Read(Y,SizeOf(Integer)); // Load Tag Information
    M.Read(Z,SizeOf(Integer)); // Load Size Information
    J1.LoadFromStream(M); // Load JPEG
    J1.SaveToFile('C:\cairnsgames\letter1.jpg'); // Write Out (to compare vs Original)
    ShowMessage(IntToStr(Z)); // Display Size info
    J1.Free;
    J.Free;
    end;[/pascal]

    And it works fine

    I think I understand what it is doing. As JPEGs allow additional information such as who took the photo, commetns and even a thumbnail of the image the load from stream seems to read from the current position in the stream until the end, but only uses the JPEG information it needs to recreate the image in memory. Therefore when you add information at the end of the stream the LoadFromStream reads right past the JPEG size and over tha additional information.

    Hope this helps.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #4

    TJPEGImage.SaveToStream problem

    Quote Originally Posted by Paulius
    When saving,
    AStream.Seek(8, LStart);
    should be
    AStream.Seek(8, soFromCurrent);
    Edit: Error 53 is "File Not Found", check msdn for error codes
    Thanks, but wouldn't soFromCurrent be the same as LStart as LStart is the current position - since the line before it is LStart := AStream.Position; ?

    Peter

  5. #5

    TJPEGImage.SaveToStream problem

    Thanks, but wouldn't soFromCurrent be the same as LStart as LStart is the current position - since the line before it is LStart := AStream.Position; ?
    No, you misunderstood the origin parameter, itis only supposed to be constants soFromBeginning, soFromCurrentg or soFromEnd. It probably defaults to one of these if the value is incorrect.

  6. #6

    TJPEGImage.SaveToStream problem

    oh, I see - thanks. The word origin makes it sound like the position you're offsetting from. It works fine now!

    Thanks for everyone's help

    Peter

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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