I have an app that print bitmaps with success for years now.
Lately, clients started to report inconsistencies. Sometimes bitmaps are
printed correctly, but sometimes the bitmap outputs as a black rectangle.
The problem occurs on HP printers only. It "seems" it appears mainly on
newly bought printers (e.g Color LaserJet 2500, Color LaserJet 4600 N) but I
also experienced the problem on a LaserJet 4000. Unfortunately, I can't
reproduce the pb at will.
The code used to print bitmap looks like this :
procedure PrintBitmap(Bitmap:TBitmap; Cnv:TCanvas; X, Y, pWidth, pHeight:
Integer);
var
Info : PBitmapInfo;
InfoSize : dword;
Image : Pointer;
ImageSize: dword;
begin
If (pWidth < 1) or (pHeight < 1) then begin
pWidth := Bitmap.Width;
pHeight := Bitmap.Height;
end;
with Bitmap do begin
GetDIBSizes(Handle, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
try
Image := AllocMem(ImageSize);
try
GetDIB(Handle, Palette, Info^, Image^);
with Info^.bmiHeader do
StretchDIBits(Cnv.Handle, X, Y, pWidth,
pHeight, 0, 0, biWidth, biHeight, Image, Info^,
DIB_RGB_COLORS, SRCCOPY)
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
end;
Any hints as to why I get those black images ?
Thanks in advance.
--
Jerome
"Jerome Bouvattier" <jerome.b...@no.thanks.fr> ha scritto nel
messaggio news:3ea7...@newsgroups.borland.com...
"Francesco Savastano" <franc...@libero.it> a écrit dans le message de
news: 3ea7...@newsgroups.borland.com...
> See Joe Hecht's explaination for such problems, that were published many
> times in this newsgroup.
> Cheers.
>
I know about TExcellentImagePrinter. If I couldn't print bitmap at all on
some printers, I would probably go for it.
But my situation is slightly different. I CAN print bitmaps on the
incriminated HP printers correctly, but from time to time, the bitmap
outputs in black (not blank).
Also clients owning those HP models do not all report the problem. All this
makes me think TExcellentImagePrinter might not solve the problem.
Since this routine served me well for years on many different printers, I
hoped someone could help me tweak it to overcome this problem.
Regards.
--
Jerome
You are correctly using the standard Standard StretchDiBits().
Past that, the only tweak available is 3500+ lines of low level code.
Try the TExcellent demo executable and see if it works. If it does,
then you will know the solution. If if does not, then it is a problem
with the given system.
Joe
--
Delphi, graphics, and printing specialist available - $35/hr
http://www.code4sale.com/codeit/index.htm
Jerome Bouvattier wrote in <3ea7...@newsgroups.borland.com>:
> The problem occurs on HP printers only. It "seems" it appears mainly on
> newly bought printers (e.g Color LaserJet 2500, Color LaserJet 4600 N) but I
> also experienced the problem on a LaserJet 4000. Unfortunately, I can't
> reproduce the pb at will.
I get a similar problem with some HP printers, if I try to print a
top-down DIB instead a (normal) bottom-up DIB. But this problem is
replicable.
...
> Info := AllocMem(InfoSize);
> try
> Image := AllocMem(ImageSize);
There are known problems with the allocation method of Delphi's Memory
Manager and GDI functions under WinNT and later.
Try to use this alternative memory allocation function (instead of
AllocMem and FreeMem):
procedure WinGetMem(var P: Pointer; Size: DWord);
begin
P := VirtualAlloc(nil, Size, MEM_COMMIT or MEM_RESERVE,
PAGE_READWRITE);
end;
procedure WinFreeMem(P: Pointer);
begin
if not VirtualFree(P, 0, MEM_RELEASE) then
RaiseLastWin32Error;
end;
More infos about this problem, you can find in:
: Newsgroups: borland.public.delphi.graphics
: Subject: BugReport: SetDIBitsToDevice / StretchDIBits on WinNT and later
: Date: Thu, 31 Oct 2002 02:55:33 +0100
: Message-ID: <3dc08d93$1...@newsgroups.borland.com>
online:
http://www.google.de/groups?threadm=3dc08d93%241%40newsgroups.borland.com
and
: Date: Wed, 16 Jan 2002 00:25:48 +0900
: Subject: Re: That (in)famous Scanline property (example) - long
: Newsgroups: borland.public.delphi.graphics
: Message-ID: <3c4448f8_1@dnews>
online:
http://www.google.de/groups?threadm=3c4448f8_1@dnews
Bye Peter.
--
Why should we be interested is someone who considers us a waste basket?
Robert Marquardt (Team JEDI) in <b4mf4g$u0k$1...@talkto.net> to me
regarding JEDI's disinterest on my contribution attempts.
Maybe JEDI users have more interest: http://jediplus.pjh2.de/index.php
I'll try your suggestions. But what do you mean by bottom-up or top-down DIB
exactly ?
--
Jerome
Thanks for your help.
Does my issue look like something familiar to you ? I mean, is
TExcellentPrinter prone to solve erratic issues like mine ? The exact same
layout on the same printer will give various results.
Sorry, I'm asking before to actually try, because testing by users won't be
very easy indeed. I trying to get as much informations as I can.
Best regards.
--
Jerome
"Joe C. Hecht" <joeh...@code4sale.com> a écrit dans le message de news:
3ea819c8$1...@newsgroups.borland.com...
Jerome Bouvattier wrote in <3ea93db6$1...@newsgroups.borland.com>:
> But what do you mean by bottom-up or top-down DIB exactly ?
The 'normally' bitmap is a bottom-up DIB. This mean, that the first line
in memory is the line at the bottom, the last line in memory is the line
at the top.
In a top-down DIB the first line in memory is the line at the top. In
this case, the bitmap have a negative Height value (field biHeight in
the TBitmapInfoHeader).
Take a look in the MSDN, e.g.:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_5jhv.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_1rw2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_7gms.asp
In the 4 years the product has been on the market, only
3 printer installations where reported to be unable to print
images using the product, not bad condisering that there
are perhaps hundereds of thousands (or millions) of deployed
installations. The product is used for everything from military
uses to the medical imaging industry.
Most of our cleints purchase our product as a last resort, and
have tried all other published solutions.
Afterall, at first is seems that it is an expensive solution for something
that should be very easy to do...
On the other hand, when you consider the savings in time, support calls,
and product returns, our customers often refer to the product as an
investment that pays huge dividends.
Give the official demo a try, and let me know how it goes.
TExcellent products can be found here: http://www.code4sale.com/joehecht/index.htm
Joe
--
Delphi, graphics, and printing specialist available - $35/hr
http://www.code4sale.com/codeit/index.htm
"Jerome Bouvattier" <jerome.b...@no.thanks.fr> wrote in message news:3ea9...@newsgroups.borland.com...