Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2005.10.23;
Скачать: [xml.tar.bz2];

Вниз

Функции BitBtl, StretchBLT дают пустую страницу на принтере   Найти похожие ветки 

 
Anatoly ©   (2005-08-17 17:41) [0]

Использую Printer для печати графического изображения.
При использовании Printer.Canvas.Pixels[i,j] все печатается ок (правда в уменьшенном масштабе и жутко медленно), а вот API-функции BitBtl(), SttretchBLT() на Printer.Canvas.Handle печатают пустой лист. Подскажите, в чем может быть проблема. GetDeviceCaps выдает capability RC_BITBLT и RC_STRETCHBLT


 
-=S.S=- ©   (2005-08-17 17:43) [1]

А ты как эти функции юзаешь ?
Т.е как потом присваеваешь канвасу принтера ?


 
Anatoly ©   (2005-08-17 17:45) [2]

...
 StretchBlt(Printer.Canvas.Handle, 0,0, 500,500, Image2.Canvas.Handle, 0, 0, 300, 300, SRCCOPY);


 
-=S.S=- ©   (2005-08-17 17:52) [3]

А чем не устраивает этот вариант ?
printer.Canvas.StretchDraw(Image1.ClientRect,Image1.Picture.Bitmap);


 
Anatoly ©   (2005-08-17 17:53) [4]

а он тоже не работает :) поэтому перешел на API


 
-=S.S=- ©   (2005-08-17 17:57) [5]

как это не работает ? :-)
Как вы картинку загружаете ?
Код в студию. Чуть шо ICQ№ 926-571


 
alpet ©   (2005-08-17 18:01) [6]

Да, привидите код пожайлуста, а то не видно как вызваются функции StartDoc, EndDoc.


 
Anatoly ©   (2005-08-17 18:01) [7]

ок. тестовый пример, который не работает:


...
 for i := 0 to 300 do
   for j := 0 to 300 do
     if (i mod 2) = 0 then
       Image2.Canvas.Pixels[i,j] := clBlack;
...
StretchBlt(Printer.Canvas.Handle, 0,0, 500,500, Image2.Canvas.Handle, 0, 0, 300, 300, SRCCOPY)


 
Anatoly ©   (2005-08-17 18:02) [8]

ну или

 printer.Canvas.StretchDraw(Image2.ClientRect,Image2.Picture.Bitmap);


 
KilkennyCat ©   (2005-08-17 18:09) [9]


> [7] Anatoly ©   (17.08.05 18:01)
> ок. тестовый пример, который не работает:


Это не тестовый пример. Это мелкий кусок кода.


 
Anatoly ©   (2005-08-17 18:09) [10]

2Applet
 Вызов StretchBlt заключен между вызовами StartDoc EndDoc


 
Anatoly ©   (2005-08-17 18:12) [11]

2KilkennyCat
 он такой и есть, но должен работать


 
KilkennyCat ©   (2005-08-17 18:13) [12]

Как распечатать картинку?

Своим кодом делится Олег Кулабухов:

--------------------------------------------------------------------------------
   uses Printers;

type
PPalEntriesArray = ^TPalEntriesArray; {for palette re-construction}
TPalEntriesArray = array[0..0] of TPaletteEntry;

procedure BltTBitmapAsDib(DestDc : hdc; {Handle of where to blt}
x : word; {Bit at x}
y : word; {Blt at y}
Width : word; {Width to stretch}
Height : word; {Height to stretch}
bm : TBitmap); {the TBitmap to Blt}
var
OriginalWidth :LongInt; {width of BM}
dc : hdc; {screen dc}
IsPaletteDevice : bool; {if the device uses palettes}
IsDestPaletteDevice : bool; {if the device uses palettes}
BitmapInfoSize : integer; {sizeof the bitmapinfoheader}
lpBitmapInfo : PBitmapInfo; {the bitmap info header}
hBm : hBitmap; {handle to the bitmap}
hPal : hPalette; {handle to the palette}
OldPal : hPalette; {temp palette}
hBits : THandle; {handle to the DIB bits}
pBits : pointer; {pointer to the DIB bits}
lPPalEntriesArray : PPalEntriesArray; {palette entry array}
NumPalEntries : integer; {number of palette entries}
i : integer; {looping variable}
begin
{If range checking is on - lets turn it off for now}
{we will remember if range checking was on by defining}
{a define called CKRANGE if range checking is on.}
{We do this to access array members past the arrays}
{defined index range without causing a range check}
{error at runtime. To satisfy the compiler, we must}
{also access the indexes with a variable. ie: if we}
{have an array defined as a: array[0..0] of byte,}
{and an integer i, we can now access a[3] by setting}
{i := 3; and then accessing a[i] without error}
{$IFOPT R+}
{$DEFINE CKRANGE}
{$R-}
{$ENDIF}

{Save the original width of the bitmap}
OriginalWidth := bm.Width;

{Get the screen"s dc to use since memory dc"s are not reliable}
dc := GetDc(0);
{Are we a palette device?}
IsPaletteDevice :=
GetDeviceCaps(dc, RASTERCAPS) and RC_PALETTE = RC_PALETTE;
{Give back the screen dc}
dc := ReleaseDc(0, dc);

{Allocate the BitmapInfo structure}
if IsPaletteDevice then
BitmapInfoSize := sizeof(TBitmapInfo) + (sizeof(TRGBQUAD) * 255)
else
BitmapInfoSize := sizeof(TBitmapInfo);
GetMem(lpBitmapInfo, BitmapInfoSize);

{Zero out the BitmapInfo structure}
FillChar(lpBitmapInfo^, BitmapInfoSize, #0);

{Fill in the BitmapInfo structure}
lpBitmapInfo^.bmiHeader.biSize := sizeof(TBitmapInfoHeader);
lpBitmapInfo^.bmiHeader.biWidth := OriginalWidth;
lpBitmapInfo^.bmiHeader.biHeight := bm.Height;
lpBitmapInfo^.bmiHeader.biPlanes := 1;
if IsPaletteDevice then
lpBitmapInfo^.bmiHeader.biBitCount := 8
else
lpBitmapInfo^.bmiHeader.biBitCount := 24;
lpBitmapInfo^.bmiHeader.biCompression := BI_RGB;
lpBitmapInfo^.bmiHeader.biSizeImage :=
((lpBitmapInfo^.bmiHeader.biWidth *
longint(lpBitmapInfo^.bmiHeader.biBitCount)) div 8) *
lpBitmapInfo^.bmiHeader.biHeight;
lpBitmapInfo^.bmiHeader.biXPelsPerMeter := 0;
lpBitmapInfo^.bmiHeader.biYPelsPerMeter := 0;
if IsPaletteDevice then begin
lpBitmapInfo^.bmiHeader.biClrUsed := 256;
lpBitmapInfo^.bmiHeader.biClrImportant := 256;
end else begin
lpBitmapInfo^.bmiHeader.biClrUsed := 0;
lpBitmapInfo^.bmiHeader.biClrImportant := 0;
end;

{Take ownership of the bitmap handle and palette}
hBm := bm.ReleaseHandle;
hPal := bm.ReleasePalette;

{Get the screen"s dc to use since memory dc"s are not reliable}
dc := GetDc(0);

if IsPaletteDevice then begin
{If we are using a palette, it must be}
{selected into the dc during the conversion}
OldPal := SelectPalette(dc, hPal, TRUE);
{Realize the palette}
RealizePalette(dc);
end;
{Tell GetDiBits to fill in the rest of the bitmap info structure}
GetDiBits(dc,
hBm,
0,
lpBitmapInfo^.bmiHeader.biHeight,
nil,
TBitmapInfo(lpBitmapInfo^),
DIB_RGB_COLORS);

{Allocate memory for the Bits}
hBits := GlobalAlloc(GMEM_MOVEABLE,
lpBitmapInfo^.bmiHeader.biSizeImage);
pBits := GlobalLock(hBits);
{Get the bits}
GetDiBits(dc,
hBm,
0,
lpBitmapInfo^.bmiHeader.biHeight,
pBits,
TBitmapInfo(lpBitmapInfo^),
DIB_RGB_COLORS);

if IsPaletteDevice then begin
{Lets fix up the color table for buggy video drivers}
GetMem(lPPalEntriesArray, sizeof(TPaletteEntry) * 256);
{$IFDEF VER100}
NumPalEntries := GetPaletteEntries(hPal,
0,
256,
lPPalEntriesArray^);
{$ELSE}
NumPalEntries := GetSystemPaletteEntries(dc,
0,
256,
lPPalEntriesArray^);
{$ENDIF}
for i := 0 to (NumPalEntries - 1) do begin
lpBitmapInfo^.bmiColors[i].rgbRed :=
lPPalEntriesArray^[i].peRed;
lpBitmapInfo^.bmiColors[i].rgbGreen :=
lPPalEntriesArray^[i].peGreen;
lpBitmapInfo^.bmiColors[i].rgbBlue :=
lPPalEntriesArray^[i].peBlue;
end;
FreeMem(lPPalEntriesArray, sizeof(TPaletteEntry) * 256);
end;

if IsPaletteDevice then begin
{Select the old palette back in}
SelectPalette(dc, OldPal, TRUE);
{Realize the old palette}
RealizePalette(dc);
end;

{Give back the screen dc}
dc := ReleaseDc(0, dc);

{Is the Dest dc a palette device?}
IsDestPaletteDevice :=
GetDeviceCaps(DestDc, RASTERCAPS) and RC_PALETTE = RC_PALETTE;

if IsPaletteDevice then begin
{If we are using a palette, it must be}
{selected into the dc during the conversion}
OldPal := SelectPalette(DestDc, hPal, TRUE);
{Realize the palette}
RealizePalette(DestDc);
end;

{Do the blt}
StretchDiBits(DestDc,
x,
y,
Width,
Height,
0,
0,
OriginalWidth,
lpBitmapInfo^.bmiHeader.biHeight,
pBits,
lpBitmapInfo^,
DIB_RGB_COLORS,
SrcCopy);

if IsDestPaletteDevice then begin
{Select the old palette back in}
SelectPalette(DestDc, OldPal, TRUE);
{Realize the old palette}
RealizePalette(DestDc);
end;

{De-Allocate the Dib Bits}
GlobalUnLock(hBits);
GlobalFree(hBits);

{De-Allocate the BitmapInfo}
FreeMem(lpBitmapInfo, BitmapInfoSize);

{Set the ownership of the bimap handles back to the bitmap}
bm.Handle := hBm;
bm.Palette := hPal;

{Turn range checking back on if it was on when we started}
{$IFDEF CKRANGE}
{$UNDEF CKRANGE}
{$R+}
{$ENDIF}
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if PrintDialog1.Execute then begin
Printer.BeginDoc;
BltTBitmapAsDib(Printer.Canvas.Handle,
0,
0,
Image1.Picture.Bitmap.Width,
Image1.Picture.Bitmap.Height,
Image1.Picture.Bitmap);
Printer.EndDoc;
end;
end;


 
alpet ©   (2005-08-17 18:13) [13]

Anatoly ©   (17.08.05 18:09) [10]

Пожайлуста код целиком, попорядку. Или на крайний случай статусы завершения всех операций (Win2k/XP - use GetLastError).


 
KilkennyCat ©   (2005-08-17 18:14) [14]

Извините за страшный формат, копи-пасте как-то не так сработал....


 
Anatoly ©   (2005-08-17 18:21) [15]

2KilkennyCat Спасибо, попробую

2Alpet


procedure TForm1.Button12Click(Sender: TObject);
var
 i, j: integer;
begin
 for i := 0 to 300 do
   for j := 0 to 300 do
     if (i mod 2) = 0 then
       Image2.Canvas.Pixels[i,j] := clBlack;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
 Printer.BeginDoc;
 StretchBlt(Printer.Canvas.Handle, 0,0, 500,500, Image2.Canvas.Handle, 0, 0, 300, 300, SRCCOPY)
 Printer.EndDoc;
end;


 
alpet ©   (2005-08-17 19:12) [16]


procedure Tmform.sbPrintClick(Sender: TObject);
var dst, src: TRect;
begin
with Printer do
try
 BeginDoc;
 img.Picture.LoadFromFile ("c:\doc\16colors.bmp");
 SetRect (dst, 0, 0, PageWidth - 1, PageHeight - 1);
 SetRect (src, 0, 0, img.Width - 1, img.Height - 1);
 Canvas.CopyRect(dst, img.Canvas, src);
 EndDoc;
except
end;

P.S: У меня нет принтера, но зато смог получить 171Мбайтный .ps (PostScript), через печать в файл. Посмотрел в GSView - вроде то что нужно. Попробуй этот код.


 
Anatoly ©   (2005-08-18 11:31) [17]

ок, спасибо, попробую


 
alpet ©   (2005-08-18 11:35) [18]

Вообще печать такими большими блоками не рекомендуется. Советую найти книгу Фень Юаня "Программирование Графики для Windows", там все хорошо расписано.



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2005.10.23;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.51 MB
Время: 0.058 c
4-1124353939
HardTouch
2005-08-18 12:32
2005.10.23
Идентификация окон


14-1128319272
WandR
2005-10-03 10:01
2005.10.23
MappedPort под FreeBSD


2-1127922780
Fl@sh
2005-09-28 19:53
2005.10.23
File+Save+..Массив класса??!!!!


11-1109533474
Гость
2005-02-27 22:44
2005.10.23
TKOLToolBar: проблема с кнопками


14-1126443842
whatisthematrix1
2005-09-11 17:04
2005.10.23
Просто зашел посмотреть...





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский