home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Image Encoders and Decoders / Transforming a JPEG Image Without Loss of Information / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-02-15  |  2.6 KB  |  88 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, GDIPAPI, GDIPOBJ, GDIPUTIL;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.dfm}
  25.  
  26. procedure TForm1.FormCreate(Sender: TObject);
  27. var
  28.   encoderClsid: TGUID;
  29.   encoderParameters: TEncoderParameters;
  30.   transformation: TEncoderValue;
  31.   width: Integer;
  32.   height: Integer;
  33.   stat: TStatus;
  34.   Image: TGPImage;
  35.   tmpstr: string;
  36. begin
  37.  
  38.    // Get a JPEG image from the disk.
  39.    Image := TGPImage.Create('..\..\Media\FRUIT.JPG');
  40.  
  41.    // Determine whether the width and height of the image 
  42.    // are multiples of 16.
  43.    width := image.GetWidth;
  44.    height := image.GetHeight;
  45.  
  46.    tmpstr := format('The width of the image is %d', [width]);
  47.    if(((width / 16.0) - (width / 16)) = 0) then
  48.       memo1.Lines.Add(tmpstr + ', which is a multiple of 16.')
  49.    else
  50.       memo1.Lines.Add(tmpstr + ', which is not a multiple of 16.');
  51.  
  52.    tmpstr := format('The height of the image is %d', [height]);
  53.    if(((height / 16.0) - (height / 16)) = 0) then
  54.       memo1.Lines.Add(tmpstr + ', which is a multiple of 16.')
  55.    else
  56.       memo1.Lines.Add(tmpstr + ', which is not a multiple of 16.');
  57.  
  58.    // Get the CLSID of the JPEG encoder.
  59.    GetEncoderClsid('image/jpeg', encoderClsid);
  60.  
  61.    // Before we call Image::Save, we must initialize an
  62.    // EncoderParameters object. The EncoderParameters object
  63.    // has an array of EncoderParameter objects. In this
  64.    // case, there is only one EncoderParameter object in the array.
  65.    // The one EncoderParameter object has an array of values.
  66.    // In this case, there is only one value (of type ULONG)
  67.    // in the array. We will set that value to EncoderValueTransformRotate90.
  68.  
  69.    encoderParameters.Count := 1;
  70.    encoderParameters.Parameter[0].Guid := EncoderTransformation;
  71.    encoderParameters.Parameter[0].Type_ := EncoderParameterValueTypeLong;
  72.    encoderParameters.Parameter[0].NumberOfValues := 1;
  73.  
  74.    // Rotate and save the image.
  75.    transformation := EncoderValueTransformRotate90;
  76.    encoderParameters.Parameter[0].Value := @transformation;
  77.    stat := image.Save('ShapesR90.jpg', encoderClsid, @encoderParameters);
  78.  
  79.    if(stat = Ok) then
  80.       memo1.Lines.Add('ShapesR90.jpg saved successfully.')
  81.    else
  82.       memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save ShapesR90.jpg failed.');
  83.  
  84.    image.Free;
  85. end;
  86.  
  87. end.
  88.