GDI+的问题:怎么才能创建并保存图形文件? 
var
  ImgD: TGPImage;
  EClsid: TGUID;
begin
  ImgD:=TGPImage.Create;
  grp:=TGPGraphics.Create(ImgD);
  brush:=TGPSolidBrush.Create(FillColor);
  grp.FillRectangle(brush,0,0,NW,NH);
  GetEncoderClsid('image/jpeg',EClsid);
  ShowMessage(GetStatus(ImgD.save('C:\1.jpg',EClsid)));结果Save失败:
---------------------------
Project1
---------------------------
InvalidParameter
---------------------------
OK   
---------------------------
  

解决方案 »

  1.   

    function TGPImage.Save(filename: WideString; const clsidEncoder: TGUID;
                   encoderParams: PEncoderParameters = nil): TStatus;
     GetEncoderClsid('image/jpeg',EClsid,nil);
      

  2.   

    var
      ImgD: TGPImage;
      EClsid: TGUID;
      Grp : TGPGraphics;
      brush: TGPSolidBrush;
      pen: TGPPen;
    begin
      ImgD:=TGPImage.Create();
      grp:=TGPGraphics.Create(ImgD);
      brush:=TGPSolidBrush.Create(makeColor(255,0,0));
      grp.FillRectangle(brush,0,0,200,200);
      pen:=TGPPen.Create(makeColor(0,0,0),5);
      grp.DrawLine(pen,1,1,100,100);
      GetEncoderClsid('image/jpeg',EClsid);
      ShowMessage(GetStatus(ImgD.save('C:\4.jpg',EClsid,nil)));也是一样不成功的。
      

  3.   

    var
     GpImage : TGPImage;
     Bmp     : TBitmap;
     Grp     : TGPGraphics;
    begin
      GpImage := TGPImage.Create('c:\1.png');
      Bmp := TBitmap.Create;
      Bmp.Width := GpImage.GetWidth;
      Bmp.Heiht := GpImage.GetHeight;
      gr := TGPGraphics.Create(Bmp.Canvas.Handle);  gr.Drawimage(GpImage,makerect(0,0,Bmp.Width,Bmp.Height),0,0,GpImage.GetWidth,Gpimage.GetHeight,UnitPixel);
      Gr.Free;
      GpImage.Free;
      Bmp.savetofile('c:\1.bmp');  
      Bmp.Free; 
      end;
      

  4.   

    以前用过,不过现在全忘光了.
    以前用的是从盒子上下载的几个PAS单元,翻译了GDI+的头文件和代码的。
    感觉用起来没这么麻烦的
      

  5.   

    TGPImage.Create 后什么都没设置.. 格式大小..
      

  6.   

    我贴一个GDI+的例子,或许对你有帮助!
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
      Dialogs, GDIPAPI, GDIPOBJ, StdCtrls;type
      TForm1 = class(TForm)
        Read: TButton;
        Memo1: TMemo;
        procedure ReadClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ReadClick(Sender: TObject);
    var
      Image: TGPImage;
      size: UINT;
      propertyItem: PPropertyItem;
      x: array[0..31] of byte;
      i:integer;
      Str: String;
    type
      ac= array of byte;
    begin
      Image:= TGPImage.Create('..\untitled.JPG');  // Assume that the image has a property item of type PropertyItemEquipMake.
      // Get the size of that property item.
      size := image.GetPropertyItemSize(PropertyTagImageTitle);  // Allocate a buffer to receive the property item.
      //propertyItem = (PropertyItem*)malloc(size);
      GetMem(propertyItem ,Size);  // Get the property item.
      image.GetPropertyItem(PropertyTagImageTitle, size, propertyItem);  // Display the members of the retrieved PropertyItem object.
      memo1.Lines.Add(format('The length of the property item is %u.', [propertyItem.length]));
      memo1.Lines.Add(format('The data type of the property item is %u.', [propertyItem.type_]));
      for i := 0 to 31 do x[i] := ac(propertyItem)[i];
      if(propertyItem.type_ = PropertyTagTypeASCII) then
      begin
        Str := PChar(propertyItem.value);
        memo1.Lines.Add(format('The value of the property item is %s.', [str]));
      end;
       freemem(propertyItem);
       image.Free;
    end;end.
      

  7.   

    下午看了下 TGPImage.Create 没找到怎么直接创建 的 lz的代码就第一行 有问题。。
      

  8.   

    晚上钻研了1个多小时,终于搞定了(但不一定是最好的方法)  TSaveDrawForm = class(TForm)
        Button: TButton;
        Image: TImage;
        procedure ButtonClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      SaveDrawForm: TSaveDrawForm;implementationuses
      GDIPAPI, GDIPOBJ, GDIPUTIL;{$R *.dfm}procedure TSaveDrawForm.ButtonClick(Sender: TObject);
    var
      Graphics: TGPGraphics;
      Bmp: TGpBitMap;
      SolidBrush: TGPSolidBrush;
      EncoderClsid: TGUID;
    begin
       //画在Bmp画布里面
       Bmp := TGpBitMap.Create(100,100, PixelFormat32bppRGB);
       Graphics := TGPGraphics.Create(Bmp);
       SolidBrush:= TGPSolidBrush.Create(MakeColor(255, 255, 0, 0));
       Graphics.FillRectangle(SolidBrush, 0, 0, 100, 100);   //显示在Image画布上
       {Image.Width := Bmp.GetWidth;
       Image.Height := Bmp.GetHeight;
       Image.Left := 0;
       Image.Top := 0; }
       Graphics := TGPGraphics.Create(Image.Canvas.Handle);
       Graphics.DrawImage(Bmp, 0, 0, Image.Width, Image.Height);   //保存为外部图片
       GetEncoderClsid('image/jpeg', EncoderClsid);
       Bmp.Save('C:\1.jpg', EncoderClsid, nil);   //释放对象
       SolidBrush.Free;
       Graphics.Free;
       Bmp.Free;
    end;
      

  9.   

    就这句有问题:
    ImgD:=TGPImage.Create;
    改为
    ImgD:=TGPImage.Create(宽度, 高度);就ok
      

  10.   

    maozefa(阿发伯)这次您老人家是真的发表谬论了哈。
      

  11.   

    maozefa(阿发伯)这次您老人家是真的发表谬论了哈
    ===================================================================================
    谁是谬论试一下不就行了吗?
      

  12.   

    ImgD:=TGPImage.Create(宽度, 高度)这个构造子只有靠maozefa(阿发伯)您老人家来写了啊。
      

  13.   

    ImgD:=TGPImage.Create(宽度, 高度)这个构造子只有靠maozefa(阿发伯)您老人家来写了啊。
    ===================================================================================
    不就是把TGpImage改为TGpBitmap吗?回错了直接指出不行吗?何必用那种口气!我用的GDI+就是自己写的,这有什么难的?
      

  14.   

    试过了,没问题,背景也是红的
    var
      ImgD: TGPImage;
      EClsid: TGUID;
      g: TGpGraphics;
      brush: TGpBrush;
      w, h: Integer;
    begin
      w := 100; h := 100;
      ImgD:=TGPBitmap.Create(w, h);
      g:=TGPGraphics.Create(ImgD);
      brush:=TGPSolidBrush.Create(aclRed);
      g.FillRectangle(brush,0,0,w,H);
      GetEncoderClsid('image/jpeg',EClsid);
      ImgD.save('C:\1.jpg',EClsid);
    end;
      

  15.   

    呵呵,这么晚了和maozefa(阿发伯)斗斗嘴,好玩。不过你肯定没有完全测试过你上面的代码,你在实际运行看看吧。
      

  16.   

    没试不会发上来的,但有可能GDI+版本兼容问题,也许要作些修改
      

  17.   

    对不起啊, maozefa(阿发伯),您老别生气。技术交流是多元化的。
      

  18.   

    to sanmaotuo(老冯) :
    我是无业人员,现在不困,不知你也是否无事,还在这里聊
      

  19.   

    冒昧问一下maozefa(阿发伯)是在什么方位?
      

  20.   

    to sanmaotuo(老冯) :
    我看过你回的很多帖,觉得你思路敏捷,每个方面都好像精通似的,说实在话,我市很佩服的,我不过是个业余爱好者,而且年纪大,记忆差,同你们是比不了的
      

  21.   

    哈哈,敢问maozefa(阿发伯)贵庚?
      

  22.   

    没有。帖子地址发过来,我欣赏一下,maozefa(阿发伯)发表了何等的谬论。
      

  23.   

    难道maozefa(阿发伯)是50年代生人??
      

  24.   

    这个贴子分数有点少,冯SIR的就放在这个贴子中给吧,相信您这样的高人也不会计较:
    http://community.csdn.net/Expert/topic/5182/5182341.xml?temp=.7231409