Google Gruppi non supporta più i nuovi post o le nuove iscrizioni Usenet. I contenuti storici continuano a essere visibili.

StretchDIBits outputs in black on HP printers

57 visualizzazioni
Passa al primo messaggio da leggere

Jerome Bouvattier

da leggere,
24 apr 2003, 09:16:2524/04/03
a
Hello,

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


Francesco Savastano

da leggere,
24 apr 2003, 09:52:1524/04/03
a
See Joe Hecht's explaination for such problems, that were published many
times in this newsgroup.
Cheers.

"Jerome Bouvattier" <jerome.b...@no.thanks.fr> ha scritto nel
messaggio news:3ea7...@newsgroups.borland.com...

Jerome Bouvattier

da leggere,
24 apr 2003, 10:23:2024/04/03
a
Hello Francesco,

"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

Joe C. Hecht

da leggere,
24 apr 2003, 13:07:1124/04/03
a
> Since this routine served me well for years on many different printers, I
> hoped someone could help me tweak it to overcome this problem.

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

Peter Haas

da leggere,
24 apr 2003, 16:52:3524/04/03
a
Hi Jerome,

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

Jerome Bouvattier

da leggere,
25 apr 2003, 09:52:3125/04/03
a
Thank you very much Peter !

I'll try your suggestions. But what do you mean by bottom-up or top-down DIB
exactly ?

--
Jerome


Jerome Bouvattier

da leggere,
25 apr 2003, 09:57:0325/04/03
a
Hello Joe,

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...

Peter Haas

da leggere,
25 apr 2003, 11:05:4225/04/03
a
Hi Jerome,

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

Joe C. Hecht

da leggere,
25 apr 2003, 16:35:2825/04/03
a
Indeed it does. TExcellentImagePrinter fixes 99% of image
printing problems right out of the box. The other >1% of
printer problems are fixed by calling a few of the options
we have enabled for those truly problematic printers.

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...

Maynard Philbrook

da leggere,
26 apr 2003, 00:55:2826/04/03
a
Try setting the copymode on the canvas handle and make sure your source image
is a 24 bit DIB prior to the
and use StretchBlt api call , that way it will simple use the GDI draw the
image onto the printer instead of you
directly by passing the Device context handling.
the BMP maybe Right side up which is not the normal like row number ordering.
usually the the first byte of imge data is the starting of the last line you
see on your canvas.
the printer driver maybe having problems with this.
using the Context method should translate that ...
0 nuovi messaggi