скрыть

скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Google  
 

Изменить режим копирования изображения



Автор: Xavier Pacheco

{
Copyright © 1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}

unit MainFrm;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type

  TMainForm = class(TForm)
    imgCopyTo: TImage;
    imgCopyFrom: TImage;
    cbCopyMode: TComboBox;
    btnDrawImages: TButton;
    btnCopy: TButton;
    procedure FormShow(Sender: TObject);
    procedure btnCopyClick(Sender: TObject);
    procedure btnDrawImagesClick(Sender: TObject);
  private
    procedure DrawImages;
    procedure GetCanvasRect(AImage: TImage; var ARect: TRect);
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.GetCanvasRect(AImage: TImage; var ARect: TRect);
var
  R: TRect;
  R2: TRect;
begin
  R := AImage.Canvas.ClipRect;
  with AImage do
  begin
    ARect.TopLeft := Point(0, 0);
    ARect.BottomRight := Point(Width, Height);
  end;
  R2 := ARect;
  ARect := R2;
end;

procedure TMainForm.DrawImages;
var
  R: TRect;
begin
  // Draw an ellipse in img1
  with imgCopyTo.Canvas do
  begin
    Brush.Style := bsSolid;
    Brush.Color := clWhite;
    GetCanvasRect(imgCopyTo, R);
    FillRect(R);
    Brush.Color := clRed;
    Ellipse(10, 10, 100, 100);
  end;

  // Draw an ellipse in img2
  with imgCopyFrom.Canvas do
  begin
    Brush.Style := bsSolid;
    Brush.Color := clWhite;
    GetCanvasRect(imgCopyFrom, R);
    FillRect(R);
    Brush.Color := clBlue;
    Ellipse(30, 30, 120, 120);
  end;

end;

procedure TMainForm.FormShow(Sender: TObject);
begin
  // Initialize the combobox to the first item
  cbCopyMode.ItemIndex := 0;
  DrawImages;
end;

procedure TMainForm.btnCopyClick(Sender: TObject);
var
  cm: Longint;
  CopyToRect,
    CopyFromRect: TRect;
begin
  // Determine the copy mode based on the combo box selection
  case cbCopyMode.ItemIndex of
    0: cm := cmBlackNess;
    1: cm := cmDstInvert;
    2: cm := cmMergeCopy;
    3: cm := cmMergePaint;
    4: cm := cmNotSrcCopy;
    5: cm := cmNotSrcErase;
    6: cm := cmPatCopy;
    7: cm := cmPatInvert;
    8: cm := cmPatPaint;
    9: cm := cmSrcAnd;
    10: cm := cmSrcCopy;
    11: cm := cmSrcErase;
    12: cm := cmSrcInvert;
    13: cm := cmSrcPaint;
    14: cm := cmWhiteness;
  else
    cm := cmSrcCopy;
  end;

  // Assign the selected copymode to Image1's CopyMode property.
  imgCopyTo.Canvas.CopyMode := cm;

  GetCanvasRect(imgCopyTo, CopyToRect);
  GetCanvasRect(imgCopyFrom, CopyFromRect);

  // Now copy Image2 onto Image1 using Image1's CopyMode setting
  imgCopyTo.Canvas.CopyRect(CopyToRect, imgCopyFrom.Canvas, CopyFromRect);
end;

procedure TMainForm.btnDrawImagesClick(Sender: TObject);
begin
  DrawImages;
end;

end.





Copyright © 2004-2016 "Delphi Sources". Delphi World FAQ




Группа ВКонтакте   Ссылка на Twitter   Группа на Facebook