0
I would like to know how to change the resolution of the device, the webcam saves up to 15mpx but I can’t change the resolution of it in my program, it keeps saving the images in size 640x480. (I’ve tried to change it with her software, but the changes only have effect on her own app).
Follows the code:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public DirectX.Capture.Filter Camera;
public DirectX.Capture.Capture CaptureInfo;
public DirectX.Capture.Filters CamContainer;
public string caminhoImagemSalva = null;
public Image CapturaImagem;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CamContainer = new DirectX.Capture.Filters();
try
{
int no_of_cam = CamContainer.VideoInputDevices.Count;
#pragma warning disable CS0162 // Unreachable code detected
for (int i = 0; i < no_of_cam; i++)
#pragma warning restore CS0162 // Unreachable code detected
{
try
{
// obtém o dispositivo de entrada do vídeo
Camera = CamContainer.VideoInputDevices[i];
// inicializa a Captura usando o dispositivo
CaptureInfo = new DirectX.Capture.Capture(Camera, null);
// Define a janela de visualização do vídeo
CaptureInfo.PreviewWindow = this.picWebCam;
// Capturando o tratamento de evento
CaptureInfo.FrameCaptureComplete += AtualizaImagem;
// Captura o frame do dispositivo
CaptureInfo.CaptureFrame();
// Se o dispositivo foi encontrado e inicializado então sai sem checar o resto
break;
}
catch (Exception ex)
{
throw ex;
}
}
{
this.TopMost = false;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
public void AtualizaImagem(PictureBox frame)
{
try
{
CapturaImagem = frame.Image;
this.picImagem.Image = CapturaImagem;
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
}
}
private void btnCaptura_Click(object sender, EventArgs e)
{
try
{
CaptureInfo.CaptureFrame();
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
}
}
private void btnSalvar_Click(object sender, System.EventArgs e)
{
try
{
//abre a opção de salvar como, para selecionar a pasta
SaveFileDialog saveFileDialog1 = new SaveFileDialog
{
Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif",
Title = "Salvar o arquivo de imagem",
InitialDirectory = @"\\MI7627\Imagens"
};
saveFileDialog1.ShowDialog();
// se o nome do arquivo não for vazio, abre para salvar
if (saveFileDialog1.FileName != "")
{
// salva a imagem por fileStream
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// Salva a imagem no formato certo
switch (saveFileDialog1.FilterIndex)
{
case 1:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case 2:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 3:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Gif);
break;
}
fs.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("Erro " + ex.Message);
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{
}
private void picWebCam_Click(object sender, EventArgs e)
{
}
}
}
Where are you setting the desired size? Note: Some cameras limit the resolution when operating in webcam mode.
– Leandro Angelo
then face this is the problem, I have researched several codes and tried in several ways, I can not set a resolution, in reality nor need to change the resolution, only set a greater than 600x400
– Felipe Deolindo
See the specifications of the camera you are using.
– Leandro Angelo