Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 3212

HOW TO CREATE A CAMERA APPLICATION ON MAC?

$
0
0

Hello.

I want to create a camera application in c++ builder 10.2.1 on MacOS.

This is my code:

//Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TCameraComponent *CameraComponent1;
	TImage *Image1;
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall CameraComponent1SampleBufferReady(TObject *Sender, const TMediaTime ATime);
	void __fastcall FormClose(TObject *Sender, TCloseAction &Action);

private:	// User declarations
    void __fastcall GetImage();
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

//Unit1.cpp
#include 
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	CameraComponent1->Quality = TVideoCaptureQuality::HighQuality;
	CameraComponent1->Active = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetImage()
{
	CameraComponent1->SampleBufferToBitmap(Image1->Bitmap, true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CameraComponent1SampleBufferReady(TObject *Sender, const TMediaTime ATime)
{
    TThread::Synchronize(TThread::Current, GetImage);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    CameraComponent1->Active = false;
}
//---------------------------------------------------------------------------

It works fine only when it is in foreground.

If it is in background, it would crash.

How can I make it work fine in background?

Best Regards,

Dean


Viewing all articles
Browse latest Browse all 3212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>