![]() |
|
Image i Siyah beyaz yazdırma - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6) +--- Konu Başlığı: Image i Siyah beyaz yazdırma (/showthread.php?tid=7934) |
Image i Siyah beyaz yazdırma - barissagir - 15-11-2024 Merhabalar aşağıdaki kodla image nesnemdeki resmimi yazdırıyorum. Lakin image renkli ise renkli yazdırıyor. Ben siyah beyaz yazdırmak istiyorum. Nasıl yapabilirim? Şimdiden Teşekkür ederim. procedure TForm1.resim_yazdir(Image:TImage); var PrintBitmap: TBitmap; begin Printer.BeginDoc; try PrintBitmap := TBitmap.Create; try PrintBitmap.Assign(Image.Picture.Graphic); Printer.Canvas.StretchDraw(Rect(0, 0, Printer.PageWidth, Printer.PageHeight), PrintBitmap); finally PrintBitmap.Free; end; finally Printer.EndDoc; end; end; Image i Siyah beyaz yazdırma - yhackup - 15-11-2024 Onun bir formülü var bu yardımcı olabilir. https://en.wikipedia.org/wiki/Grayscale Cvp: Image i Siyah beyaz yazdırma - hi_selamlar - 15-11-2024 (15-11-2024, Saat: 17:27)barissagir Adlı Kullanıcıdan Alıntı: Merhabalar aşağıdaki kodla image nesnemdeki resmimi yazdırıyorum. Merhabalar, procedure TForm1.ResimYazdirVeSiyahBeyazYap(Image: TImage); var PrintBitmap, GrayBitmap: TBitmap; x, y: Integer; PixelColor, GrayColor: TColor; GrayValue: Byte; begin Printer.BeginDoc; try PrintBitmap := TBitmap.Create; GrayBitmap := TBitmap.Create; try PrintBitmap.Assign(Image.Picture.Graphic); GrayBitmap.SetSize(PrintBitmap.Width, PrintBitmap.Height); for y := 0 to PrintBitmap.Height - 1 do for x := 0 to PrintBitmap.Width - 1 do begin PixelColor := PrintBitmap.Canvas.Pixels[x, y]; GrayValue := Round((GetRValue(PixelColor) * 0.3) + (GetGValue(PixelColor) * 0.59) + (GetBValue(PixelColor) * 0.11)); GrayColor := RGB(GrayValue, GrayValue, GrayValue); GrayBitmap.Canvas.Pixels[x, y] := GrayColor; end; Printer.Canvas.StretchDraw(Rect(0, 0, Printer.PageWidth, Printer.PageHeight), GrayBitmap); finally PrintBitmap.Free; GrayBitmap.Free; end; finally Printer.EndDoc; end; end;Kolay gelsin. Cvp: Image i Siyah beyaz yazdırma - barissagir - 15-11-2024 (15-11-2024, Saat: 20:26)hi_selamlar Adlı Kullanıcıdan Alıntı:(15-11-2024, Saat: 17:27)barissagir Adlı Kullanıcıdan Alıntı: Merhabalar aşağıdaki kodla image nesnemdeki resmimi yazdırıyorum. Monochrome u denedim. Bu seferde sayfa komple simsiyah basıyor. Image i Siyah beyaz yazdırma - COMMANDX - 16-11-2024 şunu deneyin bi Edit: yazmayı unutmuşum, USES satırında Printers olmalı
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,printers, StdCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TRGBTripleArray = array[0..MaxInt div SizeOf(TRGBTriple) - 1] of TRGBTriple;
PRGBTripleArray = ^TRGBTripleArray;
procedure TForm1.Button1Click(Sender: TObject);
var
PrintBitmap, GrayBitmap: TBitmap;
x, y: Integer;
LineSrc, LineDst: PRGBTripleArray;
GrayValue: Byte;
begin
Printer.BeginDoc;
try
PrintBitmap := TBitmap.Create;
GrayBitmap := TBitmap.Create;
try
// Resmi PrintBitmap'e yükle
PrintBitmap.Assign(Image1.Picture.Graphic);
// GrayBitmap'in boyutlarını ve formatını ayarla
GrayBitmap.Width := PrintBitmap.Width;
GrayBitmap.Height := PrintBitmap.Height;
GrayBitmap.PixelFormat := pf24bit;
// PrintBitmap üzerindeki her pikseli işleyerek GrayBitmap'e kopyala
PrintBitmap.PixelFormat := pf24bit;
for y := 0 to PrintBitmap.Height - 1 do
begin
LineSrc := PrintBitmap.ScanLine[y];
LineDst := GrayBitmap.ScanLine[y];
for x := 0 to PrintBitmap.Width - 1 do
begin
// Grayscale değeri hesapla
GrayValue := Round((LineSrc[x].rgbtRed * 0.3) +
(LineSrc[x].rgbtGreen * 0.59) +
(LineSrc[x].rgbtBlue * 0.11));
// Grayscale rengi uygula
LineDst[x].rgbtRed := GrayValue;
LineDst[x].rgbtGreen := GrayValue;
LineDst[x].rgbtBlue := GrayValue;
end;
end;
// Grayscale resmi yazdır
Printer.Canvas.StretchDraw(
Rect(0, 0, Printer.PageWidth, Printer.PageHeight),
GrayBitmap
);
finally
PrintBitmap.Free;
GrayBitmap.Free;
end;
finally
Printer.EndDoc;
end;
end;
end.
2. YOL (Aynı : TRGBTripleArray fonksiyon içine alındı) Procedure IMAGEToMono(Bm: TBitmap; ReferenceColor : TColor = clWhite); CONST PixelCountMax = 32768; TYPE pRGBTripleArray = ^TRGBTripleArray; TRGBTripleArray = ARRAY [0 .. PixelCountMax - 1] OF TRGBTriple; VAR Bmp: TBitmap; i: Integer; j: Integer; RowIn: pRGBTripleArray; // pByteArray; RowOut: pRGBTripleArray; // pByteArray; Cl: TColor; gr: Byte; begin Bmp := TBitmap.Create; Bm.PixelFormat := pf24bit; try Bmp.Width := Bm.Width; Bmp.Height := Bm.Height; Bmp.PixelFormat := Bm.PixelFormat; FOR j := 0 TO Bmp.Height - 1 DO Begin RowOut := Bmp.Scanline[j]; RowIn := Bm.Scanline[j]; i := 0; while i <= Bmp.Width - (1) do Begin Cl := RGB(RowIn[i].rgbtRed, RowIn[i].rgbtGreen, RowIn[i].rgbtBlue); if cl < ReferenceColor then gr := 0 else gr := 255; RowOut[i].rgbtRed := gr; RowOut[i].rgbtGreen := gr; RowOut[i].rgbtBlue := gr; inc(i, 1); End; end; Bm.Assign(Bmp); finally Bmp.Free; End; End; // kullanımı procedure TForm1.Button1Click(Sender: TObject); begin IMAGEToMono(IMAGE1.Picture.Bitmap, RGB(200,200,200)); end; Image i Siyah beyaz yazdırma - barissagir - 16-11-2024 Evet Bu kod çalıştır. Teşekkür ederim. |