ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Multipage TIFF compression change
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Isaev

Germany
5 Posts

Posted - Sep 02 2014 :  03:45:43  Show Profile  Reply
Hi to all,

I have a Multipage-TIFF-File(2.07MB) with LZW compression and will this convert such as to JPEG with Quality XX%
if I use XnConvert have I for:
25% - 694kB
50% - 939kB
75% - 1.18MB

if I use ImageEn have I for:
25% - 2.258MB
50% - 2.268MB
75% - 2.272MB

what do I make wrong?


var
  Image:        TIETIFFHandler;
  Stream:       TStream;
  Bitmap:       TIEBitmap;
  IO:           TImageEnIO;

begin
....
        Image  := TIETIFFHandler.Create;
        Stream := TMemoryStream.Create;
        Bitmap := TIEBitmap.Create;
        IO     := TImageEnIO.CreateFromBitmap(Bitmap);
        try
          if not Image.ReadFile(List[i]) or (Image.GetPagesCount <= 0) then
            raise Exception.Create('Fehler beim Lesen von Datei.');

          for i2 := 0 to Image.GetPagesCount - 1 do begin
            Stream.Size := 0;
            Image.WriteStream(Stream, i2);
            Stream.Position := 0;
            IO.LoadFromStream(Stream);
            if IO.Aborting then
              raise Exception.CreateFmt('Seiten-Ladefehler (%d)', [i2]);

            // JPEG Quality 25%
            IO.Params.TIFF_Compression    := ioTIFF_JPEG;
            IO.Params.TIFF_JPEGQuality    := 25;

            Stream.Size := 0;
            IO.SaveToStreamTIFF(Stream);
            Stream.Position := 0;
            if not Image.InsertPageAsStream(Stream, i2) then
              raise Exception.CreateFmt('Seiten-Speicherfehler (%d)', [i2]);
          end;

          try
            Image.WriteFile(Temp);
            TFile.SetLastWriteTimeUtc(Temp, TFile.GetLastWriteTimeUtc(List[i]));
          except
            on E: Exception do
              raise Exception.Create('Fehler beim Speichern der Datei.' + E.Message);
          end;
        finally
          Image.Free;
          Stream.Free;
          Bitmap.Free;
          IO.Free;
        end;
....
end;

xequte

38616 Posts

Posted - Sep 02 2014 :  22:17:36  Show Profile  Reply
Hi

Have you compared the properties of both the ImageEn and XnConvert images to see in what ways they differ?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Isaev

Germany
5 Posts

Posted - Sep 03 2014 :  00:25:18  Show Profile  Reply
xequte,
I do not say that the size should be exactly like with XnConvert, but
if I make quality worse, filesize must not become bigger, in any case.
look attentively, even if the quality is 25%, file is bigger than original!
Go to Top of Page

xequte

38616 Posts

Posted - Sep 03 2014 :  17:34:39  Show Profile  Reply
Hi

In your code to are adding images to the original file, rather than replacing them, so naturally the file will be bigger than the original.

If you want to convert the TIFF try using:


var
  InImage,
  OutImage :    TIETIFFHandler;
  Stream:       TStream;
  Bitmap:       TIEBitmap;
  IO:           TImageEnIO;
  i2: Integer;
begin
  InImage  := TIETIFFHandler.Create;
  OutImage  := TIETIFFHandler.Create;
  Stream := TMemoryStream.Create;
  Bitmap := TIEBitmap.Create;
  IO     := TImageEnIO.CreateFromBitmap(Bitmap);
  try
    if not InImage.ReadFile(In_File) or (InImage.GetPagesCount <= 0) then
      raise Exception.Create('Fehler beim Lesen von Datei.');

    for i2 := 0 to InImage.GetPagesCount - 1 do
    begin
      Stream.Size := 0;
      InImage.WriteStream(Stream, i2);
      Stream.Position := 0;
      IO.LoadFromStream(Stream);
      if IO.Aborting then
        raise Exception.CreateFmt('Seiten-Ladefehler (%d)', [i2]);

      // JPEG Quality 25%
      IO.Params.TIFF_Compression    := ioTIFF_JPEG;
      IO.Params.TIFF_JPEGQuality    := 25;

      Stream.Size := 0;
      IO.SaveToStreamTIFF(Stream);
      Stream.Position := 0;
      if not OutImage.InsertPageAsStream(Stream, i2) then
        raise Exception.CreateFmt('Seiten-Speicherfehler (%d)', [i2]);
    end;

    try
      OutImage.WriteFile(Out_File);
      TFile.SetLastWriteTimeUtc(Temp, TFile.GetLastWriteTimeUtc(List[i]));
    except
      on E: Exception do
        raise Exception.Create('Fehler beim Speichern der Datei.' + E.Message);
    end;
  finally
    InImage.Free;
    OutImage.Free;
    Stream.Free;
    Bitmap.Free;
    IO.Free;
  end;
end;



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Isaev

Germany
5 Posts

Posted - Sep 04 2014 :  04:45:41  Show Profile  Reply
xequte,
exactly! Thank you very much! =)
Go to Top of Page

Isaev

Germany
5 Posts

Posted - Sep 08 2014 :  01:35:58  Show Profile  Reply
With the source code the compression with the majority of the files is correct
I have another 2 "file groups".
when reading the first I receive an "Error reading from file"
the second are saved without compression despite parameters
IO.Params.TIFF_Compression := ioTIFF_JPEG;
IO.Params.TIFF_JPEGQuality := 25;

why it can be?
Example files: https://cloud.mail.ru/public/28f5f52ea3b7%2Fexamples.rar
Go to Top of Page

xequte

38616 Posts

Posted - Sep 09 2014 :  20:13:42  Show Profile  Reply
Hi

37.tiff is not a TIFF file, it is a JPEG file.

14625.unkown.tiff converted without error using the above code.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Isaev

Germany
5 Posts

Posted - Sep 10 2014 :  00:18:18  Show Profile  Reply
37.tiff is not a TIFF file, it is a JPEG file.
thanks, I have overlooked

14625.unkown.tiff converted without error using the above code.
yes, but the file of the bigger size turns out, in properties is written "without compression"
Go to Top of Page

xequte

38616 Posts

Posted - Sep 10 2014 :  13:44:58  Show Profile  Reply
Hi
quote:
yes, but the file of the bigger size turns out, in properties is written "without compression"

I do not see that. Before it was 677KB, after it is 204KB.

If you open the file in Windows notepad you will see that it is JPEG ("JFIF"). Also you can see the compression artefacts in an image viewer.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: