Firemonkey Monochrome

Firemonkey Monochrome filter har jeg kommentert andre steder. Her sier jeg bare at Firemonkey gjør om alle bilder til RGB. Så kan du tenke litt over det.

Som vanlig bruker jeg 2xTImage, en for originalen og en annen for resultatet ved design tidspunkt i RAD Studio:

Firemonkey Monochrome
Firemonkey Monochrome

Klasse deklarasjonen for Monochrome er grei, og du ser sikkert jeg har brukt den samme deklarasjonen for andre tilsvarende klasser, de er bare kommentert bort 🙂

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

#ifndef MonochromeH
#define MonochromeH
//---------------------------------------------------------------------------
#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 TForm14 : public TForm
{
__published:	// IDE-managed Components
	TImage *Image1;
	TImage *Image2;
	TButton *Cancel;
	TButton *OK;
	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;
	//TFilterGaussianBlur *myGaussianBlur;
	//TFilterBoxBlur *myBoxBlur;
	//TFilterRadialBlur *myRadialBlur;
	//TFilterDirectionalBlur *myDirectionalBlur;
	//TFilterEmboss *myEmboss;
	//TFilterPixelate * myPixelate;
	TFilterMonochrome * myMonochrome;
	__fastcall TForm14(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm14 *Form14;
//---------------------------------------------------------------------------
#endif

Implementeringen er like enkel:

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

#include <fmx.h>
#pragma hdrstop

#include "Monochrome.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm14 *Form14;
//---------------------------------------------------------------------------
__fastcall TForm14::TForm14(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm14::OnCreate(TObject *Sender)
{
 	//myGaussianBlur = new TFilterGaussianBlur(this);
	//myBoxBlur = new TFilterBoxBlur(this);
	//myRadialBlur = new TFilterRadialBlur(this);
	//myDirectionalBlur = new TFilterDirectionalBlur(this);
	//myEmboss = new TFilterEmboss(this);
	//myPixelate = new TFilterPixelate(this);
	myMonochrome = new TFilterMonochrome(this);

	 myMonochrome->Input = Image1->Bitmap;
	 //TrackBar1->Value = 25;
	 //myPixelate->BlockCount = TrackBar1->Value;
	 Image2->Bitmap = myMonochrome->Output;

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

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

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

Kjøring av dialogboksen skjer i DocPage-klassen. Denne er også lik kjøring av andre tilsvarende dialogbokser:

// --------------------------------------------------------------------------
//  				Monochrome
// --------------------------------------------------------------------------

void __fastcall DocPage::Monochrome()
{
	try
	{
		TForm14 *dlgMonochrome =  new TForm14(Application);

		dlgMonochrome->Image1->Bitmap = Image1->Bitmap;
		dlgMonochrome->Caption = _T("Monochrome");

		dlgMonochrome->myMonochrome->Input = dlgMonochrome->Image1->Bitmap;
		//dlgBoxBlur->myBoxBlur->BlurAmount = dlgBoxBlur->TrackBar1->Value / 100;
		dlgMonochrome->Image2->Bitmap = dlgMonochrome->myMonochrome->Output;


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

			// Don't forget the undo-stack

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

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

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

			Image1->Bitmap->Assign(dlgMonochrome->Image2->Bitmap);
			//Image1->Bitmap->Monochrome = true;

		}

		dlgMonochrome->DisposeOf();
	}
	catch(...)
	{
		ShowMessage("Monochrome did not succeed");
	}

}

Da gjenstår det vel bare et par bilder fra kjøring av programmet:

Firemonkey Monochrome 1
Firemonkey Monochrome 1
Firemonkey Monochrome 2
Firemonkey Monochrome 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.