Sharpen Filter i Firemonkey

Design tidspunkt i RAD Sdudio:

Sharpen Filter i Firemonkey
Sharpen Filter i Firemonkey

Bildet ovenfor viser min vanlige konstruksjon: En dialogboks med to TImage, en TrackBar og to TButton.

Klassedeklarasjonen for dialogboksen er som vanlig ganske grei:

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

#ifndef SharpenH
#define SharpenH
//---------------------------------------------------------------------------
#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 TForm5 : public TForm
{
__published:	// IDE-managed Components
	TImage *Image1;
	TImage *Image2;
	TButton *Cancel;
	TButton *OK;
	TTrackBar *TrackBar1;
	void __fastcall OnTrackBar1Change(TObject *Sender);
	void __fastcall OnCreate(TObject *Sender);
	void __fastcall CancelClick(TObject *Sender);
	void __fastcall OKClick(TObject *Sender);
private:	// User declarations
public:		// User declarations
	int iretState;
	TFilterSharpen * MySharpenFilter;

	__fastcall TForm5(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm5 *Form5;
//---------------------------------------------------------------------------
#endif

Like enkel vil implementeringen være:

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

#include <fmx.h>
#pragma hdrstop

#include "Sharpen.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm5 *Form5;
//---------------------------------------------------------------------------
__fastcall TForm5::TForm5(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm5::CancelClick(TObject *Sender)
{
	iretState = 0;
	Close();

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

}
//---------------------------------------------------------------------------
void __fastcall TForm5::OnCreate(TObject *Sender)
{
	MySharpenFilter = new TFilterSharpen(this);

	MySharpenFilter->Input = Image1->Bitmap;
	MySharpenFilter->Amount = TrackBar1->Value / 100;
	Image2->Bitmap =MySharpenFilter->Output;
}
//---------------------------------------------------------------------------
void __fastcall TForm5::OnTrackBar1Change(TObject *Sender)
{
	MySharpenFilter->Amount = TrackBar1->Value / 100;
	Image2->Bitmap = MySharpenFilter->Output;
}
//---------------------------------------------------------------------------

Koden for kjøring av dialogboksen i DocPage klassen vil være:

// --------------------------------------------------------------------------
//  				Sharpenfilter From Parent Form
// --------------------------------------------------------------------------
void __fastcall DocPage::SharpenFilter()
{
	try
	{
		TForm5 *dlgSharpen =  new TForm5(Application);

		dlgSharpen->Image1->Bitmap = Image1->Bitmap;
		dlgSharpen->Caption = _T("Sharpen");

		dlgSharpen->MySharpenFilter->Input = dlgSharpen->Image1->Bitmap;
		dlgSharpen->MySharpenFilter->Amount = dlgSharpen->TrackBar1->Value / 100;
		dlgSharpen->Image2->Bitmap = dlgSharpen->MySharpenFilter->Output;


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

			// Don't forget the undo-stack

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

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

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

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

		}

		dlgSharpen->DisposeOf();
	}
	catch(...)
	{
		ShowMessage("Sharpen filter did not succeed");
	}
}

Da gjenstår det bare et par bilder ved kjøring av Sharpen Filter i Firemonkey:

Sharpen Filter i Firemonkey (Runtime 1)
Sharpen Filter i Firemonkey (Runtime 1)

og:

Sharpen Filter i Firemonkey (Runtime 2)
Sharpen Filter i Firemonkey (Runtime 2)

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.