imgconv.pp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2003 by the Free Pascal development team
  5. Image conversion example.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}{$h+}
  13. program ImgConv;
  14. uses FPImage, FPWriteXPM, {FPWritePNG,} FPReadXPM, FPReadPNG, sysutils;
  15. var img : TFPMemoryImage;
  16. reader : TFPCustomImageReader;
  17. Writer : TFPCustomimageWriter;
  18. procedure Init;
  19. var t : char;
  20. begin
  21. T := upcase (paramstr(1)[1]);
  22. if T = 'X' then
  23. Reader := TFPReaderXPM.Create
  24. else
  25. Reader := TFPReaderPNG.Create;
  26. T := upcase (paramstr(3)[1]);
  27. if T = 'X' then
  28. Writer := TFPWriterXPM.Create
  29. else
  30. Writer := TFPWriterXPM.Create;
  31. img := TFPMemoryImage.Create(1,1);
  32. end;
  33. procedure ReadImage;
  34. begin
  35. img.LoadFromFile (paramstr(2), Reader);
  36. end;
  37. procedure WriteImage;
  38. begin
  39. img.SaveToFile (paramstr(4), Writer);
  40. end;
  41. procedure Clean;
  42. begin
  43. Reader.Free;
  44. Writer.Free;
  45. Img.Free;
  46. end;
  47. begin
  48. if paramcount <> 4 then
  49. begin
  50. writeln ('Give filename to read and to write, preceded by filetype:');
  51. writeln ('X for XPM, P for PNG');
  52. end
  53. else
  54. try
  55. Init;
  56. ReadImage;
  57. WriteImage;
  58. Clean;
  59. except
  60. on e : exception do
  61. writeln ('Error: ',e.message);
  62. end;
  63. end.