Changeset 13 for trunk/UCore.pas


Ignore:
Timestamp:
Sep 22, 2014, 5:25:11 PM (10 years ago)
Author:
chronos
Message:
  • Added: Image operation Negative image.
  • Added: Partialy implemented Image load from and save to file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r11 r13  
    66
    77uses
    8   Classes, SysUtils, FileUtil, ActnList, UProject, UGraphic, Controls, Graphics;
     8  Classes, SysUtils, FileUtil, ActnList, UProject, UGraphic, Controls, Graphics,
     9  ExtDlgs, ExtCtrls;
    910
    1011const
     
    1920
    2021  TCore = class(TDataModule)
     22    AImageNegative: TAction;
    2123    AImageGradient: TAction;
    2224    AImageMirror: TAction;
     
    3638    ActionList1: TActionList;
    3739    ImageList1: TImageList;
     40    OpenPictureDialog1: TOpenPictureDialog;
     41    SavePictureDialog1: TSavePictureDialog;
    3842    procedure AExitExecute(Sender: TObject);
     43    procedure AFileCloseExecute(Sender: TObject);
     44    procedure AFileOpenExecute(Sender: TObject);
     45    procedure AFileSaveAsExecute(Sender: TObject);
     46    procedure AFileSaveExecute(Sender: TObject);
    3947    procedure AImageClearExecute(Sender: TObject);
    4048    procedure AImageFlipExecute(Sender: TObject);
    4149    procedure AImageGradientExecute(Sender: TObject);
    4250    procedure AImageMirrorExecute(Sender: TObject);
     51    procedure AImageNegativeExecute(Sender: TObject);
    4352    procedure AImageRandomExecute(Sender: TObject);
    4453    procedure AFileNewExecute(Sender: TObject);
     
    146155end;
    147156
     157procedure TCore.AFileCloseExecute(Sender: TObject);
     158begin
     159  if not Project.Saved then AFileSave.Execute;
     160  Project.Free;
     161  FormMain.Redraw;
     162end;
     163
     164procedure TCore.AFileOpenExecute(Sender: TObject);
     165var
     166  Image: TImage;
     167begin
     168  if OpenPictureDialog1.Execute then begin
     169    Image := TImage.Create(nil);
     170    Image.Picture.LoadFromFile(OpenPictureDialog1.FileName);
     171    Image.Picture.Bitmap.BeginUpdate(True);
     172    Project.Bitmap.LoadFromCanvas(Image.Picture.Bitmap.Canvas,
     173      Point(Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height));
     174    Image.Picture.Bitmap.EndUpdate;
     175    Image.Free;
     176    FormMain.Redraw;
     177    Project.FileName := OpenPictureDialog1.FileName;
     178  end;
     179end;
     180
     181procedure TCore.AFileSaveAsExecute(Sender: TObject);
     182begin
     183  SavePictureDialog1.FileName := Project.FileName;
     184  if SavePictureDialog1.Execute then begin
     185    Project.FileName := SavePictureDialog1.FileName;
     186    AFileSave.Execute;
     187  end;
     188end;
     189
     190procedure TCore.AFileSaveExecute(Sender: TObject);
     191var
     192  Image: TImage;
     193begin
     194  if Project.FileName = '' then AFileSaveAs.Execute
     195  else begin
     196    Image := TImage.Create(nil);
     197    Image.Picture.Bitmap.SetSize(Project.Bitmap.Size.X, Project.Bitmap.Size.Y);
     198    Project.Bitmap.PaintToCanvas(Image.Picture.Bitmap.Canvas,
     199      Rect(0, 0, Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height));
     200    Image.Picture.SaveToFile(SavePictureDialog1.FileName);
     201    Image.Free;
     202    Project.Saved := True;
     203  end;
     204end;
     205
    148206procedure TCore.AImageClearExecute(Sender: TObject);
    149207begin
     
    174232end;
    175233
     234procedure TCore.AImageNegativeExecute(Sender: TObject);
     235begin
     236  Project.Bitmap.Negative;
     237  FormMain.Redraw;
     238end;
     239
    176240procedure TCore.AImageRandomExecute(Sender: TObject);
    177241begin
Note: See TracChangeset for help on using the changeset viewer.