Loading ...
Sorry, an error occurred while loading the content.

Converting BMP into JPG winthin a Msg

Expand Messages
  • cboxdd
    Hello guys, i do use the TMail2000 for getting eMails in batch mode into a large database-application. It works so far quite nice. But I often get eMails with
    Message 1 of 3 , Feb 4, 2004
    • 0 Attachment
      Hello guys,

      i do use the TMail2000 for getting eMails in batch mode into a large
      database-application.

      It works so far quite nice.

      But I often get eMails with large ScreenShots within (embedded)
      theses ScreenShots are really big (about 2,5 MB).

      So I tried to convert it into a JPG when retrieving the mail from
      POP3-Server. But I don't get it work right with the following code:

      if MyMsg.AttachList.Count > 1 then
      begin
      j:= 0;
      anzanl := MyMsg.AttachList.Count-1;
      while j <= anzanl do
      begin
      if Uppercase(ExtractFileExt(MyMsg.AttachList.Items
      [j].FileName)) = '.BMP' then
      begin
      try
      if MyMsg.AttachList.Items[j].Decoded.Size = 0 then
      MyMsg.AttachList.Items[j].Decode;
      tmp_filename := MyMsg.AttachList.Items[j].FileName;
      tmp_pic := TImage.Create(nil);
      tmp_jpg := TJPEGImage.Create;
      tmp_stream := TStream.Create;
      tmp_stream := MyMsg.AttachList.Items[j].Decoded;
      tmp_stream.Position := 0;
      tmp_pic.Picture.Bitmap.LoadFromStream(tmp_stream);
      tmp_stream.Position := 0;
      tmp_jpg.Assign(tmp_pic.Picture.Bitmap);
      tmp_jpg.CompressionQuality := 95;
      tmp_jpg.Compress;
      tmp_stream.Size := 0;
      tmp_stream.Position := 0;
      tmp_jpg.SaveToStream(tmp_stream);
      tmp_newfilename := StringReplace
      (tmp_filename,ExtractFileExt
      (tmp_filename),'.jpg',
      [rfReplaceAll, rfIgnoreCase]);
      MyMsg.AttachList.Delete(j);
      MyMsg.AttachList.Capacity := MyMsg.AttachList.Count;
      MyMsg.AttachStream
      (tmp_stream,tmp_newfilename,'',false);
      finally
      tmp_stream.free;
      tmp_pic.Free;
      tmp_jpg.Free;
      inc(j);
      end;
      end
      else
      inc(j);
      end;
      end;

      It doesn't work, that the big BMP is really removed from the
      Attachmentlist. When I access the Msg i get an exception.
      I also tried "MyMsg.AttachList.items[j].remove" but that doesn't
      work also.

      The jpg's are in the Message but also the bmp'sm that sould have
      been removed instead. Getting mad with every exception I get with
      another try. Please help me.


      Christian
    • Kunikazu OKADA
      ... 1) This code above destroys the MyMsg.AttachList . At least, you d better try this. tmp_stream.CopyFrom(MyMsg.AttachList.Items[j].Decoded); 2) ... I don t
      Message 2 of 3 , Feb 4, 2004
      • 0 Attachment
        > Hello guys,
        >
        > i do use the TMail2000 for getting eMails in batch mode into a large
        > database-application.
        >
        > It works so far quite nice.
        >
        > But I often get eMails with large ScreenShots within (embedded)
        > theses ScreenShots are really big (about 2,5 MB).
        >
        ....

        > been removed instead. Getting mad with every exception I get with
        > another try. Please help me.

        > tmp_stream := TStream.Create;
        > tmp_stream := MyMsg.AttachList.Items[j].Decoded;

        > tmp_stream.free;

        1)

        This code above destroys the MyMsg.AttachList .
        At least, you'd better try this.

        tmp_stream.CopyFrom(MyMsg.AttachList.Items[j].Decoded);


        2)
        > MyMsg.AttachList.Delete(j);
        > MyMsg.AttachList.Capacity := MyMsg.AttachList.Count;
        > MyMsg.AttachStream
        > (tmp_stream,tmp_newfilename,'',false);

        I don't like the idea of updating one Message .
        I suggest you to use 2 Message Objects,
        One for read-only and One for write-only.

        That would make your application much easier and stable.
      • cboxdd
        Thx a lot, i ll try soon. I will try to create a new MSG-Object that I put into my array of mails instead of the org MSG-Object with exchanged BMPs. But first
        Message 3 of 3 , Feb 6, 2004
        • 0 Attachment
          Thx a lot, i'll try soon.

          I will try to create a new MSG-Object that I put into my array of
          mails instead of the org MSG-Object with exchanged BMPs.

          But first I try your first code-snippet with the TStream - perhaps
          that is the reason for my exceptions.

          thanks so far, I'll post, if it works! :-)

          greetings from germany

          Christian
        Your message has been successfully submitted and would be delivered to recipients shortly.