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
 EOutOfMemory while creating mulitpage TIFF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

shaman

Poland
2 Posts

Posted - Jun 27 2012 :  04:39:07  Show Profile  Reply
Hello.

I have a problem with splitting one big multipage TIFF file into several smaller (also multipage) ones. While executing mio.SaveToFileTIFF() with more than 20-30 pages "EOutOfMemory" exception occurs.
Maybe you know some workaround or have an idea?

my piece of code:

procedure Foo(imagepath: String);
var [...];
begin
  mv := TImageEnMView.Create(nil);
  mio := TImageEnMIO.Create(nil);
  mio.AttachedMView := mv;

  stream := TFileStream.Create(imagepath, fmOpenRead);
  stream.Position := 0;

  pnum := EnumTIFFStream(stream);

  page := TMemoryStream.Create;

  i := 0;
  while i < pnum do
  begin
    page.Clear;
    ExtractTIFFImageStream(stream, page, i);

    //split when blank image
    if isBlankImage(page) then 
    begin
      mio.SaveToFileTIFF(genName()+'.tif');
      mv.Clear;
    end
    else begin
      page.Position := 0;
      mio.LoadFromStreamTIFF(page);
    end;
    Inc(i);
  end;
 
end;

fab

1310 Posts

Posted - Jun 27 2012 :  13:57:21  Show Profile  Reply
You could try to process (load and save) an image at the time. For example:

var
  imagePath: string;
  x, i, oindex, pcount: integer;
  ie: TImageEnView;
  c: TRGB;

  function getname():string;
  begin
    result := Format('%d.tif', [x])
  end;

begin
  imagePath := 'test.tiff';

  x := 0;
  ie := TImageEnView.Create(nil);
  pcount := EnumTIFFIm(imagePath);
  oindex := 0;
  for i:=0 to pcount-1 do
  begin
    ie.IO.Params.ImageIndex := i;
    ie.IO.LoadFromFile(imagePath);
    if ie.Proc.GetDominantColor(c) > 93 then
    begin
      // blank page
      inc(x);
      oindex := 0;
    end
    else
    begin
      ie.IO.Params.ImageIndex := oindex;
      if FileExists(getname()) then
        ie.IO.InsertToFileTIFF(getname())
      else
        ie.IO.SaveToFileTIFF(getname());
      inc(oindex);
    end;
  end;
  ie.Free();
end;
Go to Top of Page

shaman

Poland
2 Posts

Posted - Jun 28 2012 :  03:39:07  Show Profile  Reply
It works!
Thank you very much!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: