因為我有一個dll, 是c++ 寫的, 他的返回值是 LPBITMAPINFO lpBMI;即是 Delphi 的 TBitmapInfo, 我想問一下在 delphi中 timage中的picture.Bitmap如何 能由 TBitmapInfo 取得或轉換成bitmap內容 ?

解决方案 »

  1.   

    我這裏有一段代碼,是把內存流加載到Panel上的,你看一下吧
    var
      pBMIInfo: PBITMAPINFO;
    begin
      pBMIInfo := AllocMem(sizeof(TBITMAPINFO) + (255 * sizeof(TRGBQuad)));
      pBMIInfo^.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
      pBMIInfo^.bmiHeader.biPlanes := 1;
      pBMIInfo^.bmiHeader.biBitCount := 24;
      pBMIInfo^.bmiHeader.biCompression := BI_RGB;
      pBMIInfo^.bmiHeader.biSizeImage := 0;
      pBMIInfo^.bmiHeader.biXPelsPerMeter := 0;
      pBMIInfo^.bmiHeader.biYPelsPerMeter := 0;
      pBMIInfo^.bmiHeader.biClrUsed := 0;
      pBMIInfo^.bmiHeader.biClrImportant := 0;
      ShowVideo(sDir{文件名})
    endprocedure ShowVideo(sDir: string);
    var
      Jpeg : TJPEGImage;
      BmpS : TBitmap;
      DcS : HDC;
    begin
      try
        BmpS := TBitmap.Create;
        Jpeg := TJPEGImage.Create;
        try
          DcS := GetDc(plShow.Handle);
          Jpeg.LoadFromFile(sDir);
          BmpS.Assign(Jpeg);
          pBMIInfo^.bmiHeader.biWidth := BmpS.Width;
          pBMIInfo^.bmiHeader.biHeight := BmpS.Height;
          SetStretchBltMode(DcS, COLORONCOLOR);
          if BmpS.Height > 0 then
          begin
            StretchDIBits(DcS, 0, 0, plShow.Width,plShow.Height,
              0, 0, pBMIInfo^.bmiHeader.biWidth, pBMIInfo^.bmiHeader.biHeight,
              BmpS.ScanLine[BmpS.Height-1], pBMIInfo^, DIB_RGB_COLORS, SRCCOPY);
          end;
        except
        end;
      finally
        FreeAndNil(BmpS);
        FreeAndNil(Jpeg);
        ReleaseDC(plShow.Handle, DcS);
      end;
    end;
      

  2.   

    非常感激你 
    不好意思, 我想問一下, StretchDIBits 是什麼function?另外, 我是己經擁有 TBitmapInfo 的資料了, 但不知怎變回 bitmap出來