How to Thumb Preview in Picture Box From Thumb Impression Device - c#

I am trying to preview an image in picture box from Thumb Impression device. I am doing this successfully on button click which shows an image of my thumb on button click. But my requirement is, when i keep my thumb it should immediately shows my thumb without button click. Following is the code which i am using in button click. Please anyone guide.
private void GetMinDataBtn_Click(object sender, EventArgs e)
{
SGFingerPrintManager manager = new SGFingerPrintManager();
int deviceInfo = manager.Init(SGFPMDeviceName.DEV_AUTO);
deviceInfo = manager.OpenDevice(0);
try
{
this.m_TestMin.Initialize();
SGFPMDeviceInfoParam pInfo = new SGFPMDeviceInfoParam();
deviceInfo = manager.GetDeviceInfo(pInfo);
byte[] buffer = new byte[pInfo.ImageWidth * pInfo.ImageHeight]; //Here sometime it fails to load image through device. And sometimes it continously works without an issue.
deviceInfo = manager.GetImageEx(buffer, 0x1388, (int)this.FDxPicBox.Handle, 50);
if (manager.CreateTemplate(buffer, this.m_TestMin) == 0)
{
this.FdxToFIRBtn.Enabled = true;
this.VerifyBtn.Enabled = true;
this.StatusBar.Text = "Get Minutiae Data Success";
deviceInfo = manager.CloseDevice();
}
}
catch (Exception ex)
{
deviceInfo = manager.CloseDevice();
MessageBox.Show(ex.ToString());
this.StatusBar.Text = "Thumb data failed to get";
}
}

Related

How do I code a browse file button that lets the user upload their own STL file into a STL viewer?

I am currently trying to integrate an STL File Viewer in my WPF application. I have been using the HelixToolKit to do this and currently can display an STL/OBJ/3D file in the display, however, the location of the STL code is hard coded in the CS file. Here is my code
private const string MODEL_PATH = #"C:\FILE LOCATION ON DISK";
public MainWindow()
{
InitializeComponent();
ModelVisual3D device3D = new ModelVisual3D();
device3D.Content = Display3d(MODEL_PATH);
viewPort3d.Children.Add(device3D);
}
private Model3D Display3d(string model)
{
Model3D device = null;
try
{
//Adding a gesture here
viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);
//Import 3D model file
ModelImporter import = new ModelImporter();
//Load the 3D model file
device = import.Load(model);
}
catch (Exception e)
{
// Handle exception in case can not file 3D model
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}
I want the user to be able to import their own STL files into the viewer and view them. I tried to implement a browse button and coded it as such
public void btnBrowse_Click(object sender, RoutedEventArgs e)
{
// Create OpenFileDialog
OpenFileDialog dlg = new OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".stl";
dlg.Filter = "3D Objects (.stl)|*.stl";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string filename = dlg.FileName;
}
}
but I do not know how to handle the MODEL_PATH with this button. Any help would be greatly appreciated.
Regards
KillerSwitch
So I figured out how to do it. Here's how incase it helps anyone else in the future.
private Model3D Display3d(string model)
{
Model3D device = null;
try
{
//Adding a gesture here
viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);
//Import 3D model file
ModelImporter import = new ModelImporter();
//Load the 3D model file
device = import.Load(model);
}
catch (Exception e)
{
// Handle exception in case can not file 3D model
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}
public void btnBrowse_Click(object sender, RoutedEventArgs e)
{
string fileName;
var myDialog = new OpenFileDialog();
try
{
myDialog.Filter = "SE Model File|*.par;*.psm;*.asm;*.stl;*.obj";
if ((bool)myDialog.ShowDialog())
{
Mouse.OverrideCursor = Cursors.Wait;
fileName = myDialog.FileName;
Model3D newModel3D;
var newMOdelImporter = new ModelImporter();
var fileInf = new FileInfo(fileName);
string extn = fileInf.Extension;
if (extn == ".stl" | extn == ".STL")
{
newModel3D = newMOdelImporter.Load(fileName);
}
else
{
}
// Now launch the model in Viewport.
var device3D = new ModelVisual3D();
var lights = new DefaultLights();
device3D.Content = Display3d(fileName);
this.viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);
this.viewPort3d.Children.Clear();
this.viewPort3d.Children.Add(device3D);
this.viewPort3d.Children.Add(lights);
this.viewPort3d.ShowCoordinateSystem = true;
this.viewPort3d.ZoomAroundMouseDownPoint = true;
this.viewPort3d.ZoomExtentsWhenLoaded = true;
this.viewPort3d.ResetCamera();
this.viewPort3d.Title = "SE File : " + fileName;
// viewPort3d.ShowTriangleCountInfo = True
Mouse.OverrideCursor = Cursors.Arrow;
}
}
catch (Exception ex)
{
Mouse.OverrideCursor = Cursors.Arrow;
}
}

non-invocable member PictureBox.ImageLocation cannot be used like a method

I am working with the Windows Forms app. It connects to the Flikr website via free API key, searches images that I provide through the textBox and displays the names of the files that correspond to the keyword in the imagesListBox. When I click on the image name in the imagesListBox the image is displayed inside of the pictureBox. Now I am trying to save an image from the pictureBox and I get this error: "non-invocable member PictureBox.ImageLocation cannot be used like a method". Is there another method similar to ImageLocation which I can use to retrieve the image url address? Here is my code for the button which is supposed to save the image:
private void btnSave_Click(object sender, EventArgs e)
{
//method of saving image
try
{
if (pictureBox.Image != null)
{
//5
string filePath = PictureBox.ImageLocation();
string fileName = Path.GetFileName(filePath);
File.Copy(pictureBox.Text, Path.Combine(#"C:\", Path.GetFileName(pictureBox.Text)), true);
MessageBox.Show("The image has been saved to C drive.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
Searching and uploading images from Flikr:
private async void searchButton_Click(object sender, EventArgs e)
{
// if flickrTask already running, prompt user
if (flickrTask?.Status != TaskStatus.RanToCompletion)
{
var result = MessageBox.Show(
"Cancel the current Flickr search?",
"Are you sure?", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// determine whether user wants to cancel prior search
if (result == DialogResult.No)
{
return;
}
else
{
flickrClient.CancelPendingRequests(); // cancel search
}
}
// Flickr's web service URL for searches
var flickrURL = "https://api.flickr.com/services/rest/?method=" +
$"flickr.photos.search&api_key={KEY}&" +
$"tags={inputTextBox.Text.Replace(" ", ",")}" +
"&tag_mode=all&per_page=500&privacy_filter=1";
imagesListBox.DataSource = null; // remove prior data source
imagesListBox.Items.Clear(); // clear imagesListBox
pictureBox.Image = null; // clear pictureBox
imagesListBox.Items.Add("Loading..."); // display Loading...
// invoke Flickr web service to search Flick with user's tags
flickrTask = flickrClient.GetStringAsync(flickrURL);
// await flickrTask then parse results with XDocument and LINQ
XDocument flickrXML = XDocument.Parse(await flickrTask);
// gather information on all photos
var flickrPhotos =
from photo in flickrXML.Descendants("photo")
let id = photo.Attribute("id").Value
let title = photo.Attribute("title").Value
let secret = photo.Attribute("secret").Value
let server = photo.Attribute("server").Value
let farm = photo.Attribute("farm").Value
select new FlickrResult
{
Title = title,
URL = $"https://farm{farm}.staticflickr.com/" +
$"{server}/{id}_{secret}.jpg"
};
// clear imagesListBox
imagesListBox.Items.Clear();
// set ListBox properties only if results were found
if (flickrPhotos.Any())
{
imagesListBox.DataSource = flickrPhotos.ToList();
imagesListBox.DisplayMember = "Title";
}
else // no matches were found
{
imagesListBox.Items.Add("No matches");
}
}
Since it has been asked how I get images inside the pictureBox:
// display selected image
private async void imagesListBox_SelectedIndexChanged(
object sender, EventArgs e)
{
if (imagesListBox.SelectedItem != null)
{
string selectedURL = ((FlickrResult)imagesListBox.SelectedItem).URL;
// use HttpClient to get selected image's bytes asynchronously
byte[] imageBytes = await flickrClient.GetByteArrayAsync(selectedURL);
// display downloaded image in pictureBox
using (var memoryStream = new MemoryStream(imageBytes))
{
pictureBox.Image = Image.FromStream(memoryStream);
}
}
}
Change the line to the following. ImageLocation is a property, not a method.
string filePath = pictureBox.ImageLocation;

Delete or have Control of an Image while your Application is Using it C#

I’m using WinForms. In my form I have a picturebox. On form load, my program opens an image document into my picturebox from my C:/image directory. The problem is when my program opens that image I cannot go into my C:/image directory and delete this picture because my application is using it. When I go to C:/image directory and try to delete the picture I get this error.
My goal is to have control over the image document that means i have the ability to delete the specific document even if its being used by my application.
Test: I tested if you can delete an image while viewing it at the same time with "Windows Photo Viewer" installed into in my computer, and that application lets you. Windows photo viewer doesn't lock the images. When you delete an image from the directory the image goes away in windows photo viewer as well. I want to accomplish something similar.
Suggested code: I tried implementing this but, i think i'm implementing it incorrectly.
Image img;
using (var bmpTemp = new Bitmap("image_file_path"))
{
img = new Bitmap(bmpTemp);
}
Below i provided my code i wrote to load the picture into my picture box.
private void Form1_Load(object sender, EventArgs e) //When form load you do this:
{
try // Get the tif file from C:\image\ folder
{
string path = #"C:\image\";
string[] filename = Directory.GetFiles(path, "*.tif"); //gets a specific image doc.
pictureBox1.Load(filename[0]);
lblFile.Text = filename[0];
RefreshImage(); // refreshing and showing the new file
opened = true; // the files was opened.
Image img1 = Image.FromFile(lblFile.Text);
pictureBox1.Image = img1;
pictureBox1.Width = img1.Width;
pictureBox1.Height = img1.Height;
picWidth = pictureBox1.Width;
picHeight = pictureBox1.Height;
getRatio();
}
catch (Exception ex)
{
MessageBox.Show("No files or " + ex.Message);
}
}
Make a copy of the image file bits before creating the image:
private void Form1_Load(object sender, EventArgs e) //When form load you do this:
{
try // Get the tif file from C:\image\ folder
{
string path = #"C:\image\";
string[] filename = Directory.GetFiles(path, "*.tif"); //gets a specific image doc.
FileInfo fi = new FileInfo(filename[0]);
byte [] buff = new byte[fi.Length];
using ( FileStream fs = File.OpenRead(fileToDisplay) )
{
fs.Read(buff, 0, (int)fi.Length);
}
MemoryStream ms = new MemoryStream(buff);
Bitmap img1 = new Bitmap(ms);
opened = true; // the files was opened.
pictureBox1.Image = img1;
pictureBox1.Width = img1.Width;
pictureBox1.Height = img1.Height;
picWidth = pictureBox1.Width;
picHeight = pictureBox1.Height;
getRatio();
}
catch (Exception ex)
{
MessageBox.Show("No files or " + ex.Message);
}
}

Printing user control cuts off half an inch on top and left

I've got a custom control that I'm trying to print. I've tried changing the margin's on my window to "indent" my control, but it still cuts off the left and top. I've also tried the following in my print method:
private void bttnPrint_Click(object sender, RoutedEventArgs e)
{
UserControl hddc = HDDC;
var printDlg = new PrintDialog
{PrintTicket = {PageOrientation = PageOrientation.Landscape, PageBorderless = PageBorderless.Unknown}};
//printDlg.PrintTicket.PageMediaSize.PageMediaSizeName = PageMediaSizeName.NorthAmerica11x17;
if (printDlg.ShowDialog() == true)
{
printDlg.PrintVisual(hddc, "HDDC Report");
}
else
{
MessageBox.Show("Print Canceled");
}
}
Still, no joy. I've got the feeling there's a silly setting I'm missing, but I just can't seem to find it. Why is my print cutting off on the top and left?
public void Printing() {
try {
streamToPrint = new StreamReader (filePath);
try {
PrintDocument prd = new PrintDocument();
prd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
prd.PrinterSettings.PrinterName = printer;
// Set the page orientation to landscape.
prd.DefaultPageSettings.Landscape = true;
prd.Print();
}
finally {
streamToPrint.Close() ;
}
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
Namespace: System.Drawing.Printing
or maybe this link can help u
Page truncate in right side for landscape orientation with trimmargins using PdfSharp

Open Windows Form with opcv From wpf windows

note I am new in Wpf >
I have project that decode qr code by using opencv library throw web cam >
and it running successfully
now I wanna to using this project in new Wpf project >
after adding new wpf project and make reference to WinForms application >
and this my simple code to open WinForm >
public void runnow(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new CameraCapture.cameraCapture()); }
by ruining give me this exception >
The type initializer for 'Emgu.CV.CvInvoke' threw an exception.>
what can I do for solve this
C# code
public partial class CameraCapture : Form
{
Capture capture;
bool Capturing;
Bitmap bimap;
private Reader reader;
private Hashtable hint;
libAES libEncryption = new libAES();
string Mykey = "";
public static String dataDecrypted="";
public CameraCapture()
{
InitializeComponent();
}
private void Mains(object sender, EventArgs arg) // Start function main to encode Qr code
{
Image<Bgr, Byte> image = capture.QueryFrame();
if (image != null)
{
bimap = image.ToBitmap();
pictureBox1.Image = bimap;
reader = new QRCodeReader();
hint = new Hashtable(); // Add some elements to the hash table. There are no duplicate keys, but some of the values are duplicates.
hint.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
RGBLuminanceSource source = new RGBLuminanceSource(bimap, bimap.Width, bimap.Height); //This class is used to help decode images from files which arrive as RGB data from* Android bitmaps. It does not support cropping or rotation.
BinaryBitmap img = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Result result = null;
try
{
result = reader.decode(img, hint);
dataDecrypted = libEncryption.Decrypt(result.Text, Mykey);
}
catch
{
dataDecrypted = "";
}
if (result == null)
{
label1.Text = " no decode";
}
else
{
label4.Text = result.Text;
label1.Text = dataDecrypted;
capture.Dispose();
}
}
} // end function Main
private void btnStart_Click(object sender, EventArgs e)
{
if (capture == null)
{
try
{
capture = new Capture(); // **the exption thown here**
}
catch (NullReferenceException exception)
{
MessageBox.Show(exception.Message);
}
}
if (capture != null)
{
if (Capturing)
{
btnStart.Text = "Start Capture";
Application.Idle -= Mains;
}
else
{
btnStart.Text = "Stop Capture";
Application.Idle += Mains;
}
Capturing = !Capturing;
}
}
private void Release()
{
if (capture != null)
capture.Dispose();
}}
If you want to host WinForm in WPF, you need to use host control System.Windows.Forms.Integration.WindowsFormsHost
WPF provides many controls with a rich feature set. However, you may
sometimes want to use Windows Forms controls on your WPF pages. For
example, you may have a substantial investment in existing Windows
Forms controls, or you may have a Windows Forms control that provides
unique functionality.
Example code
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");
// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;
// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);
}
Check =>
http://msdn.microsoft.com/en-us/library/ms751761.aspx

Categories

Resources