🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.delphi.components
1 messages
1 total messages Started by Peter Hawkins Fri, 20 Oct 1995 00:00
DESPERATE - WinG in Delphi
#1
Author: Peter Hawkins
Date: Fri, 20 Oct 1995 00:00
128 lines
3790 bytes
Hello! PLEASE help!
Can anyone provide me with source code to blt a TBitmap to the screen
using WinG? All  I can get is a multicoloured blur of random pixels.
My code is as follows:
unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, WinG;

CONST
  ImageX = 320;
  ImageY = 200;



type
  TImg=record
  bi:TBitmapInfoHeader;
  bmp:TBitmap;
  end;

    pScreen = ^TScreen; {Bitmap access table}
  TScreen = RECORD
    CASE Integer OF
      0 : (ptb : ARRAY[-(ImageY-1)..0, 0..ImageX-1] OF Byte);
          {ptb = byte coord [y, x]}
      1 : (ptw : ARRAY[-(ImageY-1)..0, 0..(ImageX DIV 2)-1] OF Word);
          {ptw = word coord [y, x div 2]}
      2 : (pta : ARRAY[0..(ImageY*ImageX)-1] OF Byte);
          {pta = byte array [(y*320)+x]}
  END; {REC TScreen}

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Formpaint(Sender: TObject);
  private
    { Private declarations }
    hWinGDC:hDC;
    hOldBitmap:HBitmap;
    Orientation:Integer;
    Image:TImg;
    bmp:PScreen;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
InitWinG;
image.bmp:=TBitmap.create;
image.bmp.loadfromfile('C:\WINDOWS\ARCHES.BMP');
hWinGDC:=0;
hOldBitmap:=0;
Orientation:=1;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var hbm:hBitmap;
begin
hbm:=SelectObject(hWinGDC,hOldBitmap);
DeleteObject(hbm);
DeleteDC(hWinGDC);
image.bmp.free;
DeInitWinG;
end;

procedure TForm1.FormShow(Sender: TObject);
var hBM:hBitmap;
    p:pointer;
begin
if WinGRecommendDIBFormat(pBitmapInfo(@Image.bi)) then begin
 Image.Bi.biBitCount:=8;
 Image.Bi.bicompression:=bi_RGB;
 Orientation:=Image.bi.biheight;
 end
 else
 with image.bi do
 begin
 bisize:=Sizeof(image.bi);
 biplanes:=1;
 biBitcount:=8;
 biCompression:=Bi_RGB;
 biSizeImage:=0;
 biClrUsed:=0;
 biClrImportant:=0;
 Orientation:=1;
 end;
 {end;}
image.bi.biwidth:=Image.bmp.width;
Image.bi.biheight:=image.bmp.height*orientation;
image.bi.bisizeimage:=(image.bi.biwidth*image.bi.biHeight)*Orientation;
hWinGDC:=WinGCreateDC;
p:=nil;
hBM:=WinGCreateBitmap(hWinGDC,pBitmapInfo(@Image.bi),p{@bmp});
hOldBitmap:=SelectObject(HWinGDC,hBM);
bitblt(hWinGDC,0,0,Image.bmp.width,Image.bmp.height,Image.bmp.canvas.handle,
0,0,SRCCOPY);
{PatBlt(hWinGDC,0,0,Image.bmp.width,Image.bmp.height, BLACKNESS);}
end;

procedure TForm1.Formpaint(Sender: TObject);
begin
selectpalette(canvas.handle,image.bmp.palette,false);
realizepalette(canvas.handle);
WinGBitBlt(canvas.handle,0,0,image.bmp.width,image.bmp.height,hWinGDC,0,0);
end;

end.

I imagine I have to use GetDIBits to copy the bitmap from the TBitmap
to the WinG bitmap, but I have absolutely no idea how to do it. I have
the Borland Pascal WinG demo (flames), but that dosen't help me, as I
don't understand how it works, and it creates the bitmap as it runs.

Thanks,
Peter
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads