home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / BGISAVE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  3KB  |  87 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 436 of 612
  3. From : Trisdaresa Sumarjoso                1:272/38.0           12 Jun 93  01:02
  4. To   : Jeff Carney
  5. Subj : READING/WRITING Pointers
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  -=> Quoting Jeff Carney to All <=-
  8.  
  9.  JC> PLEASE HELP ME!!!!
  10.  JC> I am looking for a way to get an Image into a pointer (besides
  11.  JC> arrays) and write it to my disk. I am using arrays right now, and
  12.  JC> works fine, but When  I get big images I run out of mem fast...  ::
  13.  JC> IBUF : array [1..30000] of byte; getimage(x1,y1,x2,y2,IBUF);
  14.  JC> repeat
  15.  JC> Write(f,IBUF[NUM]);
  16.  JC> num:=num+1;
  17.  JC> until num=sizeof(ibuf);
  18.  JC> This works as long as I dont try to grab a large image.
  19.  JC> Any comments are welcome.....  Please reply...
  20.  JC> Jeff Carney
  21.  
  22.         Hello Jeff...
  23.         I grab following code from a larger work of mine. This is just a
  24.         little modified version of the image saver part. No need to say,
  25.         this handle only a very limited image (anything that is less than
  26.         64k in BGI format). And in procedure RESTOREIMAGE, you will be
  27.         better of finding your image size using FILESIZE function, since
  28.         this procedures assume one file per image.}
  29.  
  30. Program TestingSaveImage;
  31. Uses
  32.     Graph, Crt;
  33.  
  34. Procedure SaveImage( X1, Y1, X2, Y2: Integer;
  35.                      FileName: String);
  36. Var
  37.    FileToSave   : File;
  38.    I            : Integer;
  39.    PointImage   : Pointer;
  40.    Size         : Word;
  41. Begin
  42.      Assign(FileToSave, FileName);
  43.      Size := ImageSize(X1, Y1, X2, Y2);
  44.      ReWrite(FileToSave, Size);
  45.      GetMem(PointImage, Size);
  46.      GetImage(X1, Y1, X2, Y2, PointImage^);
  47.      BlockWrite(FileToSave, PointImage^, 1);
  48.      FreeMem(PointImage, Size);
  49.      Close(FileToSave);
  50. End;
  51.  
  52. Procedure RestoreImage( X1, Y1, X2, Y2: Integer;
  53.                         FileName: String);
  54. Var
  55.    FileToSave   : File;
  56.    I            : Integer;
  57.    PointImage   : Pointer;
  58.    Size         : Word;
  59. Begin
  60.      Assign(FileToSave, FileName);
  61.      Size := ImageSize(X1, Y1, X2, Y2);
  62.      Reset(FileToSave, Size);
  63.      GetMem(PointImage, Size);
  64.      BlockRead(FileToSave, PointImage^, 1);
  65.      PutImage(X1, Y1, PointImage^, CopyPut);
  66.      FreeMem(PointImage, Size);
  67.      Close(FileToSave);
  68. End;
  69.  
  70. Var
  71.    Gd, Gm       : Integer;
  72.  
  73. Begin
  74.      Gd := Detect;
  75.      InitGraph(Gd, Gm, 'c:\bp\bgi');
  76.      Bar(0, 0, GetMaxX, GetMaxY);
  77.      SaveImage(0, 0, 100, 100, 'Testing.Dat');
  78.      Repeat
  79.      Until ReadKey = #13;
  80.      ClearViewPort;
  81.      Repeat
  82.      Until ReadKey = #13;
  83.      RestoreImage(0, 0, 100, 100, 'Testing.Dat');
  84.      Repeat
  85.      Until ReadKey = #13;
  86.      CloseGraph;
  87. End.