Article View: borland.public.delphi.nativeapi
Article #7GetDIBits and GetLastError=8
From: jf.jouvet
Date: Mon, 16 Jun 2003 07:41
Date: Mon, 16 Jun 2003 07:41
168 lines
4356 bytes
4356 bytes
Hello
In the Felowing code I got Error n�8 : No space enough to execute this
command ('Pas assez d'espace pour traiter cette commansde'), Some times
at the first loop, some times at the 2� or 3�
I dont see my mistake(s), I dont understand why, and what I can do
In Win200, I try it on some PC with 256 or 512 mb memory: same error
Thanks in advance for any help
Jean Francois Jouvet
Here is the code
NB Image..BMP is a BMP file 768 column, 576 lines, 256 gray level
(pf8bit)
Unit uLoadImage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ D�clarations priv�es }
public
{ D�clarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
CONST
MAXPLAN = 2;
NBLIG = 576;
NBCOL = 768;
TYPE
tPlan = record
Image : Array of byte;
TypePlan : integer;
end;
VAR
PimHeader : tBitMapInfo;
Plan : array[0..MAXPLAN] of tPlan;
NumPlan : integer;
procedure DelPlan;
var i : integer;
begin
for i := 0 to MAXPLAN do begin
with Plan[i] do begin
SetLength(Image,0);
Image := nil;
TypePlan := 0;
end;
end;
end;
FUNCTION INITPLAN: boolean;
var i : integer;
begin
i := 0;
while (i <= MAXPLAN) do
begin
TRY
with Plan[i] do
begin
SetLength(Image, NBCOL*NBLIG);
TypePlan := 1;
end;
inc(i);
EXCEPT
dec(i);
ShowMessage('INITPLAN : '+SysErrorMessage(GetLastError) +' '+
IntToStr(i));
END;
end;
Result := (i >= MAXPLAN);
end;
function Load_Image(var NumPlan: integer; FileName: String): Boolean;
var
hdc_local : hdc;
BitMap : tBitMap;
Error : dWord;
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile(pChar(FileName));
hdc_local := GetDc(Form1.Handle);
if BitMap.PixelFormat=pf8Bit then
begin
if GetDIBits(hdc_local,
Bitmap.Handle,
0, word(NBLIG),
Plan[NumPlan].Image,
PimHeader,
DIB_RGB_COLORS) = 0 then
begin
Result := false;
Error:=GetLastError;
ShowMessage(IntToStr(Error)+' '+SysErrorMessage(Error));
end
else Result := true;
end
else Result := false;
ReleaseDC(Form1.Handle, hdc_local);
BitMap.Free;
GDIFlush;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with PimHeader.BmiHeader do
begin
biSize := sizeof(tBITMAPINFOHEADER);
biWidth := NBCOL;
biHeight := -NBLIG;
biPlanes := 1;
biBitCount := 8;
biCompression := 0;
biSizeImage := NBCOL*NBLIG;
biXPelsPerMeter := 0;
biYPelsPerMeter := 0;
biClrUsed := 0;
biClrImportant := 0;
end;
InitPlan;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
NumPlan := 0;
for i := 0 to MAXPLAN do
begin
if Load_Image(NumPlan,'Image.bmp') then inc(NumPlan);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DelPlan;
end;
end.
Technical Details
Message-ID:
<3EED74A8.504B2119@opales.fr>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f94dd,d6883c76481cb771,start X-Google-Attributes: gidf94dd,public X-Google-Thread: 10a296,d6883c76481cb771,start X-Google-Attributes: gid10a296,public X-Google-ArrivalTime: 2003-06-16 00:46:26 PST Message-ID: <3EED74A8.504B2119@opales.fr> Date: Mon, 16 Jun 2003 09:41:28 +0200 From: "jf.jouvet" <jf.jouvet@opales.fr> X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: fr,en MIME-Version: 1.0 Newsgroups: borland.public.delphi.nativeapi,borland.public.delphi.graphics Subject: GetDIBits and GetLastError=8 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 193.252.28.240 X-Trace: newsgroups.borland.com 1055749170 193.252.28.240 (16 Jun 2003 00:39:30 -0700) Lines: 170 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail