take a snapshot from wecam by using DShowNET library - c#

how can i make a snapshot in my cod:
using DirectX.Capture;
using DShowNET;
private void Form1_Shown(object sender, EventArgs e)
{
DirectX.Capture.Capture capture = null;
Filters filters = null;
capture = new DirectX.Capture.Capture(filters.VideoInputDevices[deviceNo], filters.AudioInputDevices[0]);
capture.PreviewWindow = pictureBox1;
}
private void _Pause_Click(object sender, EventArgs e)
{
//??
}
i want to convert pictureBox1's video stream to a image by clicking on "Pause" button.
and then save pictureBox1's pic(*.jpg) to data base.

Related

WebBrowser.DocumentCompleted and Navigate - C#

I'm trying to modify a simple application which use the WebBrowser item:
private void button1_Click(object sender, EventArgs e)
{
var menu = webBrowser1.Document.GetElementById("SomeItem").InvokeMember("click");
webBrowser1.Visible = true;
button1.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Visible = false;
webBrowser1.AllowNavigation = true;
webBrowser1.Navigate("domain");
}
This works fine, the page load and then after clicking the button the user is redirected to the desired location.
Now I'm trying to make this without the help of the button.
Simply put the button code inside the load function didn't help, so I've introduced in my code the DocumentCompleted event.
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.AllowNavigation = true;
webBrowser1.Navigate("SomeDomain");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentComplete);
}
private void wb_DocumentComplete(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = sender as WebBrowser;
wb.Document.GetElementById("SomeItem").InvokeMember("click");
}
By debugging it, I saw that the wb object is correctly instantiated with the "domain" but I got System.NullReferenceException when I try to retrieve SomeItem.
The document is not fully loaded because I'm still in the load function ?

Continuous Playing of Different Video Files in a VLC Playlist

I am trying to play different video files continuously on VLC player on my Winform application.
The problem I face is between different playlist videos there is a 1-2 seconds of black screen.
How can I play all videos in my playlist smoothly without any waiting?
private void buttonLoad_Click(object sender, EventArgs e)
{
var uri = new Uri(#"C:\Users\Val\Downloads\000013.ts");
var converted = uri.AbsoluteUri;
var uri2 = new Uri(#"C:\Users\Val\Downloads\000210.ts");
var converted2 = uri2.AbsoluteUri;
axVLCPlugin21.playlist.add(converted);
axVLCPlugin21.playlist.add(converted2);
}
private void buttonStart_Click(object sender, EventArgs e)
{
axVLCPlugin21.MediaPlayerEndReached += new EventHandler(OnTimedEvent);
axVLCPlugin21.playlist.playItem(0);
}
private void OnTimedEvent(object sender, EventArgs e)
{
axVLCPlugin21.playlist.playItem(1);
}
this is a simplified version of what I am trying to do.
When the player reaches end of the first video file it starts the second on by eventhandler function.
The best way I know to play videos seamlessly is to avoid the timed event in your example:
private void buttonLoad_Click(object sender, EventArgs e)
{
var uri = new Uri(#"C:\Users\Val\Downloads\000013.ts");
var converted = uri.AbsoluteUri;
var uri2 = new Uri(#"C:\Users\Val\Downloads\000210.ts");
var converted2 = uri2.AbsoluteUri;
axVLCPlugin21.playlist.add(converted);
axVLCPlugin21.playlist.add(converted2);
}
private void buttonStart_Click(object sender, EventArgs e)
{
axVLCPlugin21.playlist.play();
}

Windows Phone uploading images to azure blob service

I want to upload a photo from my phone to azure blob.
Im using this link
http://www.windowsazure.com/en-us/develop/mobile/tutorials/upload-images-to-storage-wp8/
there is no error or a exception, it just i cant see it and i know the binding is correct,
even when i open the link of the image, there is no photo found.
there is a question similar to this one here
Upload image to Azure blob storage from Windows Phone. Not creating
This is what I'm doing
PhotoChooserTask chooser;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Refresh();
base.OnNavigatedTo(e);
}
private void PhotoChooserBtn_Click(object sender, RoutedEventArgs e)
{
chooser = new PhotoChooserTask();
chooser.Completed += chooser_Completed;
chooser.Show();
}
Stream stream = null;
void chooser_Completed(object sender, PhotoResult e)
{
stream = e.ChosenPhoto;
BitmapImage sourceImg = new BitmapImage();
sourceImg.SetSource(stream);
ProfileImage.Source = sourceImg;
}
async private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
Images images = new Images() { Username = "7elbeh" };
InsertImage(images);
}
private void RefreshBtn_Click(object sender, RoutedEventArgs e)
{
Refresh();
}
please help.
I have the same error, to solve i convert my Stream to array and use UploadFromByteArrayAsync
byte[] array = imageStream.ToArray();
await blobFromSASCredential.UploadFromByteArrayAsync(array, 0, array.Length);

Saving images using Aforge

i wrote a code for accessing webcam and on clicking, saving the picture to a folder.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video;
using AForge.Video.DirectShow;
namespace cam
{
public partial class Form1 : Form
{
public static Bitmap _latestFrame;
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;
Bitmap bitmap;
private void Form1_Load(object sender, EventArgs e)
{
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
}
comboBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
bitmap = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bitmap;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Image = bitmap;
}
private void button3_Click(object sender, EventArgs e)
{
if (cam.IsRunning)
{
cam.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap current = (Bitmap)_latestFrame.Clone();
string ActiveDir = AppDomain.CurrentDomain.BaseDirectory;
string filepath = System.IO.Path.Combine(ActiveDir, #"D://picture/");
if (!System.IO.Directory.Exists(filepath))
{
System.IO.DirectoryInfo OutputDir = System.IO.Directory.CreateDirectory(filepath);
string fileName = System.IO.Path.Combine(filepath, #"name.bmp");
if (!System.IO.File.Exists(fileName))
{
current.Save(fileName);
}
}
current.Dispose();
}
}
}
In the button2 I have written the code for saving the picture, on building the program, an null reference exception is shown for the given line(Bitmap current = (Bitmap)_latestFrame.Clone();)
As far as I can see in your code, the new image frame is copied to your member variable bitmap. The static member _latestFrame never seem to be assigned.
Therefore, in your button2_Click method, change the first line to:
Bitmap current = (Bitmap)bitmap.Clone();
Now, provided you have received at least one frame from the webcam when you click the button, the frame should be properly saved.
I also think you are overworking the filepath setting in the button2_Click method. To begin with, simply verify that the picture can be properly saved to the active directory by changing your button2_Click method to this:
private void button2_Click(object sender, EventArgs e)
{
Bitmap current = (Bitmap)bitmap.Clone();
string filepath = Environment.CurrentDirectory;
string fileName = System.IO.Path.Combine(filepath, #"name.bmp");
current.Save(fileName);
current.Dispose();
}
This will ensure that a new image will be written to the "current directory" every time you click on the Capture button.
I have tested your code with the above changes, and it works flawlessly.

Unable to preview multiple page tiff files in .Net

I'm trying to preview and print multiple page TIFF files from a C# 2005 Windows application. Printing works fine but when I send my PrintDocument to a PrintPreviewDialog I get two images of the first page rather than an ameage of the first and second page. I also have the same problem when I use PrintPreviewControl.
Below is code for a form with 2 buttons, a PrintDocument and a PrintPreviewDialog that demonstrates the problem.
public partial class Form1 : Form
{
private Image m_Image;
private Int32 m_CurrentPage;
private Int32 m_PageCount;
private void Form1_Load(object sender, EventArgs e)
{
m_Image = Image.FromFile(".\\Test-2-Page-Image.tif");
m_PageCount = m_Image.GetFrameCount(FrameDimension.Page);
}
private void printDocument_BeginPrint(object sender, PrintEventArgs e)
{
m_CurrentPage = 0;
m_PageCount = m_Image.GetFrameCount(FrameDimension.Page);
}
private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
m_Image.SelectActiveFrame(FrameDimension.Page, m_CurrentPage);
e.Graphics.DrawImage(m_Image, 0, 0);
++m_CurrentPage;
e.HasMorePages = (m_CurrentPage < m_PageCount);
}
private void btnPreview_Click(object sender, EventArgs e)
{
printPreviewDialog.Document = printDocument;
printPreviewDialog.ShowDialog();
}
private void btnPrint_Click(object sender, EventArgs e)
{
printDocument.Print();
}
}
Does anyone know if there is there a problem with the PrintPreviewDialog in the .Net framework or am I doing something wrong.
It's a bug with the Graphics.DrawImage() function.
The problem is documented here: Graphics.DrawImage Bug
The working code looks like this:
img.SelectActiveFrame(FrameDimension.Page, curPage);
using(MemoryStream stm = new MemoryStream())
{
img.Save(stm, imgCodecInfo, encParams); // save to memory stream
Bitmap bmp = (Bitmap)Image.FromStream(stm);
e.Graphics.DrawImage((Image)bmp,0,0);
bmp.Dispose();
}

Categories