Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Image i Siyah beyaz yazdırma
#1
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;
Cevapla
#2
Onun bir formülü var bu yardımcı olabilir.
https://en.wikipedia.org/wiki/Grayscale
WWW
Cevapla
#3
(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.
Cevapla
#4
(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.
Cevapla
#5
ş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.
Cevapla
#6
Evet Bu kod çalıştır.

Teşekkür ederim.
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Image raporlama nevzatc 1 557 03-03-2026, Saat: 14:53
Son Yorum: nevzatc
  Crystal Reports - Yazdırma iletişim kutusunda yazıcı seçimi devre dışı delphiX14 2 605 26-01-2026, Saat: 18:52
Son Yorum: frmman
  Barkod etiketi yazdırma sorunu Zebra tlp2844 HalilK. 1 948 21-01-2025, Saat: 14:48
Son Yorum: mcuyan
  label creare te caption yazdırma sorunu ercanskose 1 815 12-09-2024, Saat: 11:27
Son Yorum: ercanskose
  Image Compare bydelphi 4 1.293 01-07-2024, Saat: 08:50
Son Yorum: bydelphi



Konuyu Okuyanlar: 1 Ziyaretçi