Pencil Stroke Filter

Enda et filter fra Firemonkey kolleksjonen, Pencil Stroke Filter, her ved design tidspunkt:

Firemonkey Pencil Stroke Filter
Firemonkey Pencil Stroke Filter

Av bildet ovenfor ser du jeg bruker 2xTImage, en for originalen og en annen for resultatet. Det er også satt på en TTrackbar.

Klasse deklarasjonen er også for denne ganske enkel:

//---------------------------------------------------------------------------

#ifndef PencilStrokeH
#define PencilStrokeH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Effects.hpp>
#include <FMX.Filter.Effects.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm16 : public TForm
{
__published:	// IDE-managed Components
	TImage *Image1;
	TImage *Image2;
	TTrackBar *TrackBar1;
	TButton *CancelButton;
	TButton *OKButton;
	void __fastcall TrackBar1Change(TObject *Sender);
	void __fastcall CancelButtonClick(TObject *Sender);
	void __fastcall OKButtonClick(TObject *Sender);
	void __fastcall OnCreate(TObject *Sender);
private:	// User declarations
public:		// User declarations
	int iretState;
	TFilterPencilStroke * MyPencilStroke;

	__fastcall TForm16(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm16 *Form16;
//---------------------------------------------------------------------------
#endif

Implementeringen likeså:

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "PencilStroke.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm16 *Form16;
//---------------------------------------------------------------------------
__fastcall TForm16::TForm16(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm16::TrackBar1Change(TObject *Sender)
{
	MyPencilStroke->brushSize = TrackBar1->Value;
	Image2->Bitmap = MyPencilStroke->Output;

}
//---------------------------------------------------------------------------
void __fastcall TForm16::CancelButtonClick(TObject *Sender)
{
	iretState = 0;
	Close();

}
//---------------------------------------------------------------------------
void __fastcall TForm16::OKButtonClick(TObject *Sender)
{
	iretState = 1;
	Close();

}
//---------------------------------------------------------------------------
void __fastcall TForm16::OnCreate(TObject *Sender)
{
	MyPencilStroke = new TFilterPencilStroke(this);

	MyPencilStroke->Input = Image1->Bitmap;
	MyPencilStroke->brushSize = TrackBar1->Value;
	Image2->Bitmap = MyPencilStroke->Output;

}
//---------------------------------------------------------------------------

Kallet på dialogboksen skjer i DocPage klassen:

// --------------------------------------------------------------------------
//  			Pencil Stroke From Parent Form
// --------------------------------------------------------------------------

void __fastcall DocPage::PencilStroke()
{
	//
	try
	{
		TForm16 *dlgPencilStroke =  new TForm16(Application);

		dlgPencilStroke->Image1->Bitmap = Image1->Bitmap;
		dlgPencilStroke->Caption = _T("PencilStroke");

		dlgPencilStroke->MyPencilStroke->Input = dlgPencilStroke->Image1->Bitmap;
		dlgPencilStroke->TrackBar1->Value = 5;
		dlgPencilStroke->MyPencilStroke->brushSize = dlgPencilStroke->TrackBar1->Value;
		dlgPencilStroke->Image2->Bitmap = dlgPencilStroke->MyPencilStroke->Output;

		dlgPencilStroke->ShowModal();
		if( dlgPencilStroke -> iretState == 1 ) {

			// Don't forget the undo-stack

			UndoItem = new TUndoItem();
			UndoItem->UndoName = new String("PencilStroke");
			UndoItem->UndoBitmap = new TBitmap();

			// Have to use "Assign()" because everything are pointers!!!

			UndoItem->UndoBitmap->Assign(Image1->Bitmap);
			mystack.push(UndoItem);

			Image1->Bitmap->Assign(dlgPencilStroke->Image2->Bitmap);

		}

		dlgPencilStroke->DisposeOf();

	}
	catch(...)
	{
		ShowMessage("Pencil Stroke filter did not succeed");
	}

}

Da gjenstår det vel bare et par bilder fra runtime, slik at du ser det hele funker:

Firemonkey Pencil Stroke runtime 1
Firemonkey Pencil Stroke runtime 1
Firemonkey Pencil Stroke runtime 2
Firemonkey Pencil Stroke runtime 2