Aforge Program works only on Debug mode - c#

am trying to make streaming video using aforge on visual studio windows forms
in debug mode everything works well but after publishing it the picturebox that is used to show the video still white
Here is the code
if (device != null && cboDevice.Items.Count != 0)
{
if (firstim != null)
{
pictureBox1.Image = firstim;
}
device = new VideoCaptureDevice(filter[cboDevice.SelectedIndex].MonikerString);
device.NewFrame += new NewFrameEventHandler( Device_NewFrame);
device.Start();
private void Form1_Load(object sender, EventArgs e)
{
filter = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach(FilterInfo dev in filter)
cboDevice.Items.Add(dev.Name);
cboDevice.SelectedIndex = 0;
device = new VideoCaptureDevice();
}
private void button4_Click(object sender, EventArgs e)
{
if (device != null && cboDevice.Items.Count != 0)
{
device = new VideoCaptureDevice(filter[cboDevice.SelectedIndex].MonikerString);
device.NewFrame += Device_NewFrame;
device.Start();
}
}

Related

Toast notification does not pop up when zoom records screen in .net WPF App

I am working on a .NET WPF project using Visual Studio 2022 and I added tray icon functionality to my app. I also show toast notification whenever my app is minimized to windows tray. Everything works fine except when i am on a zoom meeting and screen recording, toast notification does not show up. What could be the reason for this?
My code:
public NotifyIcon m_notifyIcon;
public MainWindow()
{
InitializeComponent();
m_notifyIcon = new NotifyIcon();
m_notifyIcon.BalloonTipText = "The app has been minimised. Click the tray icon to show.";
m_notifyIcon.BalloonTipTitle = "The App";
m_notifyIcon.Text = "The App";
m_notifyIcon.DoubleClick += new EventHandler(m_notifyIcon_Click);
m_notifyIcon.MouseDown += new MouseEventHandler(Notifier_MouseDown);
Hide();
if (m_notifyIcon != null)
m_notifyIcon.ShowBalloonTip(2000);
CheckTrayIcon();
}
}
private WindowState m_storedWindowState = WindowState.Normal;
void OnStateChanged(object sender, EventArgs args)
{
if (WindowState == WindowState.Minimized)
{
Hide();
if (m_notifyIcon != null)
m_notifyIcon.ShowBalloonTip(2000);
}
else
m_storedWindowState = WindowState;
}
void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs args)
{
CheckTrayIcon();
}
void m_notifyIcon_Click(object sender, EventArgs e)
{
Show();
WindowState = m_storedWindowState;
}
void CheckTrayIcon()
{
ShowTrayIcon(true);
}
void ShowTrayIcon(bool show)
{
if (m_notifyIcon != null)
m_notifyIcon.Visible = show;
}
void Notifier_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ContextMenu menu = (ContextMenu)this.FindResource("NotifierContextMenu");
menu.IsOpen = true;
IntPtr handle = ((HwndSource)PresentationSource.FromVisual(menu)).Handle;
ApiHelper.SetForegroundWindow(handle);
}
}

C# Combox.text string always shows empty string within Timer tick function

I have an application where combox text get populated with data, I have two timer function to read the combox text content, one timer works fine, but the other time always shows combox content is always empty string. I am wondering where things are wrong
private void AddNewDataToSystemButton_Click(object sender, EventArgs e)
{
if (tbAddTrainTrainID.Text != "" && tbAddTrainRegionID.Text != "" && tbAddTrainSegmentID.Text != "")
{
bool isTrainAdded = CommonStore.TrainSimMainDatabase.AddNewTrainInToSystem(Convert.ToInt32(tbAddTrainTrainID.Text),
Convert.ToByte(tbAddTrainRegionID.Text), Convert.ToByte(tbAddTrainSegmentID.Text));
CommonStore.TrainSimMainDatabase.InitializingTrainCollection[Convert.ToInt32(tbAddTrainTrainID.Text)].VehicleList.IsManualTrain = false;
if (isTrainAdded)
{
cbTrainList.Items.Add(tbAddTrainTrainID.Text);
cbRemoveTrainID.Items.Add(tbAddTrainTrainID.Text);
}
else
{
TrainChangeRequestResponse.Text = "Train already exists in the system.";
}
}
}
private void Timer1_Tick(object sender, EventArgs e)
{
if (CommonStore.TrainSimMainDatabase != null)
{
if (CommonStore.TrainSimMainDatabase.InitializingTrainCollection.Count > 0 && cbTrainList.Text != "")
{
// huge code
}
}
}
public void VATCTimer_Tick(object sender, EventArgs e)
{
if (cbTrainList.Text != "")
{
\\ huge code

Admob InterstitialAd event handler doesn't get called

I'm writing an Ad Controller in unity3d. I found strange problem with event handlers related with interstital ads.
Method that I use to request interstitial:
private void GoogleRequestInterstitial(string gameID)
{
if (string.IsNullOrEmpty(gameID))
{
Debug.LogErrorFormat("GoogleAds - Game ID can't be NULL or EMPTY!");
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Game ID can't be NULL or EMPTY!");
}
var interstitial = new InterstitialAd(gameID);
AdRequest request = null;
if (CallbackMethod != null)
{
interstitial.AdFailedToLoad += InterstitialOnAdFailedToLoad;
interstitial.AdClosed += InterstitialOnAdClosed;
interstitial.AdClosing += InterstitialOnAdClosing;
interstitial.AdLeftApplication += InterstitialOnAdLeftApplication;
interstitial.AdLoaded += InterstitialOnAdLoaded;
interstitial.AdOpened += InterstitialOnAdOpened;
}
else
{
Debug.LogWarningFormat("GoogleAds - Don't forget to register callback!");
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Don't forget to register callback!");
}
if (DebugMode)
{
request = new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator.
.AddTestDevice("2077ef9a63d2b398840261c8221a0c9b") // My test device.
.Build();
}
else
{
request = new AdRequest.Builder().Build();
}
interstitial.LoadAd(request);
controller.StartCoroutine(GoogleShowAdWhenReady(interstitial));
}
Corutine:
private IEnumerator GoogleShowAdWhenReady(InterstitialAd interstitial)
{
while (!interstitial.IsLoaded())
yield return null;
interstitial.Show();
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial : SHOW");
}
Here is whole event handlers region:
#region EventHandlers - INTERSTITIAL
private void InterstitialOnAdClosed(object sender, EventArgs args)
{
CallbackMethod(WinzebraAdsController.WinzebraShowResult.Finished);
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "FINISHED");
var obj = sender as InterstitialAd;
obj.Destroy();
}
private void InterstitialOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
CallbackMethod(WinzebraAdsController.WinzebraShowResult.Failed);
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "FAILED !");
var obj = sender as InterstitialAd;
obj.Destroy();
}
private void InterstitialOnAdClosing(object sender, EventArgs eventArgs)
{
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Closing");
}
private void InterstitialOnAdOpened(object sender, EventArgs eventArgs)
{
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Opened");
}
private void InterstitialOnAdLoaded(object sender, EventArgs eventArgs)
{
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Loaded");
}
private void InterstitialOnAdLeftApplication(object sender, EventArgs eventArgs)
{
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Left Application");
}
#endregion
Info:
WinzebraAdsConsole is self-written "console" based on Text component.
CallbackMethod is custom "global" callback and this is allways NOT NULL (checked before).
On first run i can see in self-written console that methods InterstitialOnAdLoaded and InterstitialOnAdOpened runs properly. But problem starts when im close interstitial and event InterstitialOnAdClosed doesn't get called.
Additionally on second run of interstitial i get event InterstitialOnAdClosing but still not "OnClosed".
Is there any problem with my code? Anyone see that kind of problem before?
Screenshoots:
After first interstitial:
After second interstitial:
I think there is no need to define another Co-routine to wait will the ad is read to display, instead try this may fix your issue:
private void InterstitialOnAdLoaded(object sender, EventArgs eventArgs)
{
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial On Ad Loaded");
if (interstitial.IsLoaded())
{
interstitial.Show();
if (WinzebraAdsConsole.Instance != null) WinzebraAdsConsole.Instance.WriteLine(TagGoogleAds, "Interstitial : SHOW");
}
}

Windows phone picturebox

I'm developing an windows phone 8.1 application in C#. I'm using the camera to take a picture. The picture is than saved on the device and I'm trying to show it in a picturebox.
I have tested it on a HTC phone and it worked nice, but when i tried it on a Nokia Lumia the picture would never load.
Does anyone have an idea how to solve that?
Here is the code I am sing to take a picture:
private void snap_task_Click(object sender, EventArgs e)
{
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += cameraCaptureTask_Completed;
cameraCaptureTask.Show();
}
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
NavigationService.Navigate(new Uri("/Slika.xaml?fotka=" + e.OriginalFileName, UriKind.Relative));
}
}
And this is the code where I try toload the picture.
public Slika()
{
InitializeComponent();
string slika = string.Empty;
string slika2 = string.Empty;
this.Loaded += (s, e) =>
{
if (NavigationContext.QueryString.TryGetValue("fotka", out slika))
{
putanja = slika; /*"/Resources/" + slika + ".png";/**/
int x = putanja.Length;
if (x == 1)
{
putanja = "/Resources/" + putanja + ".png";
uriPutanja = new Uri(putanja, UriKind.Relative);
fotka = new BitmapImage(uriPutanja);
}
else
{
uriPutanja = new Uri(putanja, UriKind.Relative);
porukaTextBox.Text = putanja;
fotka = new BitmapImage(uriPutanja);
}
}
img1.Source = fotka;
};
}
PS
the loading from local resources works fine on both phones, it is just the "else" part of the if that is causing problems on the Nokia.
You are saving the image in the Camera roll folder in your phone, try saving it on your memory card instead and try if that works (you an just change it in the setting of the phone and say to save the new pictures on the SD card) If that works, try using the PhotoChooserTask in order to get the image.
I hope that the following code will help you:
using Microsoft.Phone.Tasks;
using System.IO;
using System.Windows.Media.Imaging;
...
PhotoChooserTask selectphoto = null;
private void button1_Click(object sender, RoutedEventArgs e)
{
selectphoto = new PhotoChooserTask();
selectphoto.Completed += new EventHandler(selectphoto_Completed);
selectphoto.Show();
}
void selectphoto_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BinaryReader reader = new BinaryReader(e.ChosenPhoto);
image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
}
}
You can try changing the UriKind from Relative to Absolute. If I have understood your code, you will get the absolute path to the picture.
As I understand the code you have forgotten the .png in the else case.

capture image from webcam c# WPF app

I'm trying to capture images from a webcam for one application in WPF/C#
1) I tried WIA but i het the error 0x80210015, I have read that this error occurs when there is no WIA device available. I read that in windows vista/7 WPD is used insted WIA but when i try a simple example
PortableDeviceManager deviceManager = new PortableDeviceManager();
deviceManager.RefreshDeviceList();
uint numberOfDevices = 1;
deviceManager.GetDevices(null, ref numberOfDevices);
if (numberOfDevices == 0)
{
Console.WriteLine("No device");
}
else
{
string[] deviceIds = new string[numberOfDevices];
deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices);
Console.WriteLine(deviceIds);
}
Console.Read();
i cant detect devices.
2) I triead with http://easywebcam.codeplex.com/ works, but i get randomly the error "An error occured while capturing the video image. The video captu..." and i need select the device always and i need execute webcam.start() several times (2 or 3) for that camera works.
I have two webcams
Chicony Web 2.0 (inbuilt webcam)
Genius FaceCam 2000
here is a simple take a picture kind of program
Image<Bgr, Byte> img;
private Capture capture;
private bool captureInProgress;
private void gumb_kamera_Click(object sender, EventArgs e)
{
}
private void processFunction(object sender, EventArgs e)
{
img = capture.QueryFrame();
// imageBox1.Image = img;
}
private void Form1_Load(object sender, EventArgs e)
{
if (capture == null)
{
try
{
capture = new Capture(0);
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
if (capture != null)
{
if (captureInProgress)
{
Application.Idle -= processFunction;
}
else
{
Application.Idle += processFunction;
}
captureInProgress = !captureInProgress;
}
}
private void button1_Click(object sender, EventArgs e)
{
imageBox1.Image = img;
}

Categories

Resources