I have a camera device in device there is button in camera to capture the image I have having a issue when I capture the image with camera device the camera location is not in original size and image is cutting when I click on the form save button the image location is in original size and image is not cutting can anyone can help this is code when I capture the image with camera device button
private void videoDevice_SnapshotFrame(object sender, NewFrameEventArgs eventArgs)
{
Console.WriteLine(eventArgs.Frame.Size);
ShowSnapshot((Bitmap)eventArgs.Frame.Clone());
}
private void ShowSnapshot(Bitmap snapshot)
{
if (InvokeRequired)
{
Invoke(new Action<Bitmap>(ShowSnapshot), snapshot);
}
else
{
if (snapshotForm == null)
{
snapshotForm = new SnapshotForm();
snapshotForm.FormClosed += new FormClosedEventHandler(snapshotForm_FormClosed);
snapshotForm.Show();
}
snapshotForm.SetImage((Bitmap)snapshot.Clone());
if (!string.IsNullOrWhiteSpace(patientIDInput))
{
string folderPath = folderNewPath;
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
string fileName = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss") + ".jpg";
string filePath = Path.Combine(folderPath, fileName);
snapshot.Save(filePath, ImageFormat.Jpeg);
ShowMessageBoxNew("Image saved successfully.", "Caption", 3);
guna2HtmlLabel1.Text = "Saved to: " + filePath;
snapshotForm.Close();
snapshotForm = null;
}
}
}
>and this is a snapshotForm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace Sojro.Myforms
{
public partial class SnapshotForm : Form
{
public SnapshotForm()
{
InitializeComponent();
}
public void SetImage(Bitmap bitmap)
{
timeBox.Text = DateTime.Now.ToLongTimeString();
lock (this)
{
Bitmap old = (Bitmap)pictureBox.Image;
pictureBox.Image = bitmap;
if (old != null)
{
old.Dispose();
}
}
}
private void PictureBox_Click(object sender, EventArgs e)
{
Process.Start("umer.exe");
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Escape))
{
this.Close();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void SnapshotForm_Load(object sender, EventArgs e)
{
}
private void Guna2Button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
and this a code when i save the image with form save button
private void guna2Button2_Click(object sender, EventArgs eventArgs)
{
guna2Button2.BackgroundImage = global::Sojro.Properties.Resources._4383919;
if (!string.IsNullOrWhiteSpace(patientIDInput))
{
_cameraType = "camera";
Dermascope_Load(sender, null);
string folderPath = folderNewPath;
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
int MaxCount = 5;
int Count = 0;
var snapshot = snapshotHandler.TakeSnapshot();
while (snapshot == null && Count < MaxCount)
{
snapshot = snapshotHandler.TakeSnapshot();
Count++;
if (snapshot == null)
{
System.Threading.Thread.Sleep(1000);
}
}
if (snapshot != null)
{
var img = (System.Drawing.Image)snapshot.ToImage();
if (img != null)
{
int newWidth = 1350;
int newHeight = 650;
var resizedImg = new Bitmap(img, newWidth, newHeight);
string fileName = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss tt") + ".jpg";
string filePath = Path.Combine(folderPath, fileName);
resizedImg.Save(filePath, ImageFormat.Jpeg);
resizedImg.Dispose();
ShowMessageBoxNew("Image saved successfully.", "Caption", 3);
guna2HtmlLabel1.Text = "Saved to: " + filePath;
}
else
{
MessageBox.Show("Failed to capture the snapshot.");
}
}
}
What I have tried:
Can any one help me with the above issue please