Yorumları: 174
Konuları: 62
Kayıt Tarihi: 14-11-2020
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 286 Acemi
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;
Yorumları: 2.165
Konuları: 261
Kayıt Tarihi: 09-08-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 4.679 Uzman
Onun bir formülü var bu yardımcı olabilir.
https://en.wikipedia.org/wiki/Grayscale
Yorumları: 856
Konuları: 40
Kayıt Tarihi: 11-11-2016
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 4.385 Uzman
15-11-2024, Saat: 20:26
(Son Düzenleme: 16-11-2024, Saat: 06:55, Düzenleyen: hi_selamlar.)
(15-11-2024, Saat: 17:27)barissagir Adlı Kullanıcıdan Alıntı: 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;
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.
Amaç, bilginin de/aklın da zekat'ını vermek.
Yorumları: 174
Konuları: 62
Kayıt Tarihi: 14-11-2020
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 286 Acemi
(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.
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;
Merhabalar,
var
PrintBitmap: TBitmap;
begin
Printer.BeginDoc;
try
PrintBitmap := TBitmap.Create;
try
PrintBitmap.Assign(Image.Picture.Graphic);
PrintBitmap.Monochrome := True;
Printer.Canvas.StretchDraw(Rect(0, 0, Printer.PageWidth, Printer.PageHeight), PrintBitmap);
finally
PrintBitmap.Free;
end;
finally
Printer.EndDoc;
end;
Kolay gelsin.
Monochrome u denedim. Bu seferde sayfa komple simsiyah basıyor.
Yorumları: 181
Konuları: 16
Kayıt Tarihi: 16-01-2021
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 1.059 Programcı
16-11-2024, Saat: 08:15
(Son Düzenleme: 18-11-2024, Saat: 09:38, Düzenleyen: COMMANDX.)
ş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;
__________________________
From Now I will only Reading.
Yorumları: 174
Konuları: 62
Kayıt Tarihi: 14-11-2020
Aktif Kullandığınız Delphi Sürümü:
Rep Puanı: 286 Acemi
Evet Bu kod çalıştır.
Teşekkür ederim.
|