home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d3456 / POWERPDF.ZIP / PowerPdf / PdfJpegImage.pas < prev    next >
Pascal/Delphi Source File  |  2001-09-15  |  2KB  |  76 lines

  1. {*
  2.  * << P o w e r P d f >> -- PdfJpegImage.pas
  3.  *
  4.  * Copyright (c) 1999-2001 Takezou. <takeshi_kanno@est.hi-ho.ne.jp>
  5.  *
  6.  * This library is free software; you can redistribute it and/or modify it
  7.  * under the terms of the GNU Library General Public License as published
  8.  * by the Free Software Foundation; either version 2 of the License, or any
  9.  * later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13.  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
  14.  * details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public License
  17.  * along with this library.
  18.  *
  19.  * 2001.06.14 create
  20.  * 2001.09.07 changes the implementation of TPdfImageCreator.
  21.  *
  22.  *}
  23. unit PdfJpegImage;
  24.  
  25. interface
  26.  
  27. uses
  28.   SysUtils, Classes, Graphics, PdfTypes, PdfDoc, PdfImages, JPEG;
  29.  
  30. type
  31.   { TPdfJpegImage }
  32.   TPdfJpegImage = class(TPdfImageCreator)
  33.   public
  34.     function CreateImage(AImage: TGraphic): TPdfImage; override;
  35.   end;
  36.  
  37. implementation
  38.  
  39. // CreateImage
  40. function TPdfJpegImage.CreateImage(AImage: TGraphic): TPdfImage;
  41. begin
  42.   // check whether specified graphic is valid image.
  43.   if not (AImage is TJpegImage) then
  44.     raise EPdfInvalidValue.Create('only jpeg image is allowed.');
  45.  
  46.   result := TPdfImage.CreateStream(nil);
  47.   with result do
  48.   try
  49.     TJpegImage(AImage).SaveToStream(Stream);
  50.     with Attributes do
  51.     begin
  52.       AddItem('Type', TPdfName.CreateName('XObject'));
  53.       AddItem('Subtype', TPdfName.CreateName('Image'));
  54.       AddItem('ColorSpace', TPdfName.CreateName('DeviceRGB'));
  55.       AddItem('Width', TPdfNumber.CreateNumber(AImage.Width));
  56.       AddItem('Height', TPdfNumber.CreateNumber(AImage.Height));
  57.       AddItem('BitsPerComponent', TPdfNumber.CreateNumber(8));
  58.       PdfArrayByName('Filter').AddItem(TPdfName.CreateName('DCTDecode'));
  59.     end;
  60.   except
  61.     result.Free;
  62.     raise;
  63.   end;
  64.  
  65. end;
  66.  
  67. initialization
  68.  
  69.   RegisterClassAlias(TPdfJpegImage, 'Pdf-Jpeg');
  70.  
  71. finalization
  72.  
  73.   UnRegisterClass(TPdfJpegImage);
  74.  
  75. end.
  76.