Firemonkey Paper Sketch

OK, jeg prøver meg på et nytt eksempel med Firemonkey biblioteket, Paper Sketch. Jeg synes ikke resultatet ble verdens beste akkurat, men du får ta en titt.

På vanlig måte bruker jeg 2xTImage, en for originalen og en for resultatet. Dessuten skal det her være med en TTrackBar:

Firemonkey Paper Sketch Design
Firemonkey Paper Sketch Design

Klasse deklarasjonen:

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

#ifndef PaperSketchH
#define PaperSketchH
//---------------------------------------------------------------------------
#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 TForm17 : public TForm
{
__published:	// IDE-managed Components
	TImage *Image1;
	TImage *Image2;
	TTrackBar *TrackBar1;
	TButton *CancelButton;
	TButton *OKButton;
	void __fastcall OnCreate(TObject *Sender);
	void __fastcall TrackBar1Change(TObject *Sender);
	void __fastcall CancelButtonClick(TObject *Sender);
	void __fastcall OKButtonClick(TObject *Sender);
private:	// User declarations
public:		// User declarations
	int iretState;
    TFilterPaperSketch * MyPaperSketch;

	__fastcall TForm17(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm17 *Form17;
//---------------------------------------------------------------------------
#endif

Klasse implementeringen:

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

#include <fmx.h>
#pragma hdrstop

#include "PaperSketch.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm17 *Form17;
//---------------------------------------------------------------------------
__fastcall TForm17::TForm17(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm17::OnCreate(TObject *Sender)
{
	MyPaperSketch = new TFilterPaperSketch(this);

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

}
//---------------------------------------------------------------------------
void __fastcall TForm17::TrackBar1Change(TObject *Sender)
{
	MyPaperSketch->brushSize = TrackBar1->Value;
	Image2->Bitmap = MyPaperSketch->Output;

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

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

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

Formen, eller dialogboksen, ovenfor kjøres i DocPage klassen:

// --------------------------------------------------------------------------
//  			Paper Sketck From Parent Form
// --------------------------------------------------------------------------

void __fastcall DocPage::PaperSketch()
{
	//
	try
	{
		TForm17 *dlgPaperSketch =  new TForm17(Application);

		dlgPaperSketch->Image1->Bitmap = Image1->Bitmap;
		dlgPaperSketch->Caption = _T("Paper Sketch");

		dlgPaperSketch->MyPaperSketch->Input = dlgPaperSketch->Image1->Bitmap;
		dlgPaperSketch->TrackBar1->Value = 3;
		dlgPaperSketch->MyPaperSketch->brushSize = dlgPaperSketch->TrackBar1->Value;
		dlgPaperSketch->Image2->Bitmap = dlgPaperSketch->MyPaperSketch->Output;

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

			// Don't forget the undo-stack

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

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

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

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

		}

		dlgPaperSketch->DisposeOf();

	}
	catch(...)
	{
		ShowMessage("Paper Sketch filter did not succeed");
	}

}

Da gjenstår det vel kun et par bilder fra kjøringen:

Firemonkey Paper Sketch filter
Firemonkey Paper Sketch filter
Firemonkey Paper Sketch filter
Firemonkey Paper Sketch filter

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *

Dette nettstedet bruker Akismet for å redusere spam. Lær om hvordan dine kommentar-data prosesseres.