试图将IPictureDisp转换成TPicture在Image控件中显示,使用SetOlePicture,能够成功。但是当进一步将Image中的图片进行保存时出错了。
procedure TForm1.ConvertIP(const dd: IPictureDisp);
begin
   SetOlePicture(Image1.Picture, dd);
   Image1.Picture.SaveToFile('C:\1.bmp');
end;提示‘Interface not supported’
为何不能保存?
该如何保存?多谢!

解决方案 »

  1.   

    显示的是什么格式的图片?如果是BMP那保存时要加上头等信息。
      

  2.   

    显示的是tif文件。不一定要保存为bmp格式,也可以是jpg格式,该怎么做?
      

  3.   

    你的图片格式是tif的,那我网上查下如何转换成其它格式
      

  4.   

    谢谢xisiyong.
    通过以上方法可以实现图像格式转换吗?有没有其他例子?
      

  5.   

    继续顶。
    现在的目的主要是将IPictureDisp中的图片取出来,或者送到内存流中,不知道怎么操作。请大侠帮忙。
      

  6.   

    setOlePicture,QGraphic.TPicture..........
      

  7.   

    Uses
     AxCtrls;var
    bmp: TBitmap;
    Picture:TPicture;
    PictureAdapter :TPictureAdapter;MyPicDisp:IPictureDisp;begin
     bmp := TBitmap.Create;
     try
       bmp.LoadFromFile(FileName);//当然也可以直接由TPicture来Load
       Picture := TPicture.Create;
       try
         Picture.Assign(bmp);
         GetOlePicture(Picture,MyPicDisp);//这里由TPicture得到IPictureDisp
       finally
         Picture.Free;
       end;
     finally
       bmp.Free;
     end;
    end; 
      

  8.   

    Itestimage = interface(IDispatch)
       ['{DBE43759-A55C-4B11-951D-A5466BC0642D}']
       function Get_image: IPictureDisp; safecall;
       procedure Set_image(const Value: IPictureDisp); safecall;
       property image: IPictureDisp read Get_image write Set_image;function Ttestimage.Get_image: IPictureDisp;
    var
     picture:Tpicture;
     BitMap:TBitMap;
    var
     DeskWnd,   DeskDC:LongWord;
    begin
     picture:=Tpicture.Create;
     DeskWnd:=GetDesktopWindow();
     DeskDC:=GetDC(DeskWnd);
     BitMap:=TBitMap.Create;
     try
         BitMap.Width:=Screen.Width;
         BitMap.Height:=Screen.Height;
         Bitblt(BitMap.Canvas.Handle,0,0,Screen.Width,Screen.Height,
                       DeskDC,0,0,SRCCOPY);
         Picture.Assign(Bitmap);
         GetOlePicture(Picture,Result);//
     finally
       ReleaseDC(DeskWnd,DeskDC);
       picture.Free;
     end;
    end;procedure SaveHBmpToStream(const bmpHandle: HBITMAP;Stream: TStream); 
    var 
     ds: TDIBSection; 
     BmpFileHeader:  TBitmapFileHeader; 
     NumberOfColors,BitCount: Integer; 
     Bm: tagBITMAP; 
     Bytes: integer; 
    begin 
     if Stream = nil then 
       raise Exception.Create('Stream无效'); 
     Stream.Size := 0; 
     Bytes := GetObject(bmpHandle,SizeOf(ds),@ds); //获得有关DIBSECTION结构中的点阵图资讯 
     if Bytes = 0 then 
       raise Exception.Create('无效的位图文件'); 
     Bytes := GetObject(bmpHandle,SizeOf(bm),@Bm);//获得tagBITMAP结构 
     if Bytes = 0 then 
       raise Exception.Create('无效的位图文件'); 
     try 
       NumberOfColors := ds.dsBmih.biClrUsed;//获得调色板中实际使用的颜色数 
       BitCount := ds.dsBmih.biBitCount;//位图位数 
       if (NumberOfColors = 0) and (BitCount <= 8) then 
         NumberOfColors := 1 shl BitCount; 
       With BmpFileHeader do 
       begin 
         bfType := $4D42;  // 'BM'位图标记 
         bfReserved1 := 0; 
         bfReserved2 := 0; 
         bfOffBits := SizeOf(TBitmapFileHeader)      + 
                     SizeOf(TBitmapInfoHeader)      + 
                     NumberOfColors*SizeOf(TRGBQuad); //获得信息头大小 
         bfSize := bfOffBits + ds.dsBmih.biSizeImage; //获得文件大小 
       end; 
       Stream.Write(BmpFileHeader,sizeof(BITMAPFILEHEADER)); 
       Stream.Write(ds.dsBmih,sizeof(TBITMAPINFOHEADER)); 
       stream.Write(Bm.bmBits^, ds.dsBmih.biSizeImage); 
       Stream.Seek(0,soFromBeginning); 
       Ini.WriteString('成功','SaveHBmpToStream','调用procedure SaveHBmpToStream(const bmpHandle: HBITMAP;Stream: TStream);成功'); 
     except 
       on E: Exception do 
         MessageBox(application.Handle,PChar(E.Message),'错误',16); 
     end; 
    end;  procedure SaveHBmpToStream(const bmpHandle: HBITMAP;Stream: TStream);
    var
     ds: TDIBSection;
     BmpFileHeader:  TBitmapFileHeader;
     NumberOfColors,BitCount: Integer;
     Bm: tagBITMAP;
     Bytes: integer;
    begin
     if Stream = nil then
       raise Exception.Create('Stream无效');
     Stream.Size := 0;
     Bytes := GetObject(bmpHandle,SizeOf(ds),@ds); //获得有关DIBSECTION结构中的点阵图资讯
     if Bytes = 0 then
       raise Exception.Create('无效的位图文件');
     Bytes := GetObject(bmpHandle,SizeOf(bm),@Bm);//获得tagBITMAP结构
     if Bytes = 0 then
       raise Exception.Create('无效的位图文件');
     try
       NumberOfColors := ds.dsBmih.biClrUsed;//获得调色板中实际使用的颜色数
       BitCount := ds.dsBmih.biBitCount;//位图位数
       if (NumberOfColors = 0) and (BitCount <= 8) then
          NumberOfColors := 1 shl BitCount;
       With BmpFileHeader do
       begin
         bfType := $4D42;  // 'BM'位图标记
         bfReserved1 := 0;
         bfReserved2 := 0;
         bfOffBits := SizeOf(TBitmapFileHeader)       +
                      SizeOf(TBitmapInfoHeader)       +
                      NumberOfColors*SizeOf(TRGBQuad); //获得信息头大小
         bfSize := bfOffBits + ds.dsBmih.biSizeImage; //获得文件大小
       end;
       Stream.Write(BmpFileHeader,sizeof(BITMAPFILEHEADER));
       Stream.Write(ds.dsBmih,sizeof(TBITMAPINFOHEADER));
       stream.Write(Bm.bmBits^, ds.dsBmih.biSizeImage);
       Stream.Seek(0,soFromBeginning);
       TStream);成功');
     except
       on E: Exception do
         MessageBox(application.Handle,PChar(E.Message),'错误',16);
     end;
    end;
      

  9.   

    谢谢飞飞和玲玲。你给的似乎不是我要的结果啊。我已经得到IPictureDisp,通过SetOlePicture保存到picture中,应该怎么取出来保存?