我用的是这个函数:GdipSaveImageToFile(gdip_Graphics,StrToWideChar('c:\1.bmp'),nil,nil);
其中,第一个参数gdip_Graphics确认里面有内容的,为什么确生成不到 c:\1.bmp文件呢?

解决方案 »

  1.   

    第二个参数不能为nil供参考:
    function GetEncoderClsid(format: WideString; var Clsid: TGUID): Boolean;
    var
      num, size, i: Integer;
      ImageCodecInfo: PImageCodecInfo;
    type
      InfoArray = array of TImageCodecInfo;
    begin
      num  := 0;
      size := 0; 
      Result := False;  GetImageEncodersSize(num, size);
      if (size = 0) then exit;  GetMem(ImageCodecInfo, size);
      try
        GetImageEncoders(num, size, ImageCodecInfo);
        i := 0;
        while (i < num) and (CompareText(InfoArray(ImageCodecInfo)[i].MimeType, format) <> 0) do
          Inc(i);
        Result := i < num;
        if Result then
          Clsid := InfoArray(ImageCodecInfo)[i].Clsid;
      finally
        FreeMem(ImageCodecInfo, size);
      end;
    end;var
      Clsid: TGUID;
    begin
      if GetEncoderClsid('image/bmp', Clsid) then
        GdipSaveImageToFile(gdip_Graphics,StrToWideChar( 'c:\1.bmp '),Clsid,nil);
    end;
     
      

  2.   

    为什么不直接使用TGpImage或者TGpBitmap呢?
      

  3.   

    const
      GDIImageFormatBMP:  TGUID = '{557CF400-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatJPG:  TGUID = '{557CF401-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatGIF:  TGUID = '{557CF402-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatEMF:  TGUID = '{557CF403-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatWMF:  TGUID = '{557CF404-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatTIFF: TGUID = '{557CF405-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatPNG:  TGUID = '{557CF406-1A04-11D3-9A73-0000F81EF32E}';
      GDIImageFormatICO:  TGUID = '{557CF407-1A04-11D3-9A73-0000F81EF32E}';TGPImage.Save(filename: WideString; const clsidEncoder: TGUID);例子:
    procedure TBossPubServerWindow.actSaveToFileExecute(Sender: TObject);
    begin
      inherited;  dlgSaveToFile.FileName := FrmStencil.StencilName;
      if not Assigned(FrmGraphics) or not dlgSaveToFile.Execute then Exit;  case dlgSaveToFile.FilterIndex of
        1: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatBMP);
        2: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatJPG);
        3: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatGIF);
        4: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatEMF);
        5: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatWMF);
        6: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatTIFF);
        7: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatPNG);
        8: FrmGraphics.SaveToFile(dlgSaveToFile.FileName, GDIImageFormatICO);
      end;
    end;如果是位图,GDIImageFormatEMF、GDIImageFormatWMF和GDIImageFormatWMF不支持!