Changed final statements on Bitmap conversion to allow for memory stream

This commit is contained in:
Ted Pickard 2021-02-17 17:55:43 -08:00
parent d98547c786
commit 61b11bc9ee
3 changed files with 20 additions and 9 deletions

View File

@ -3,10 +3,11 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.Threading;
using System.Windows.Forms;
using System.Text;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using GreatHomeChildcare.Models;
using System.IO;
namespace GreatHomeChildcare
{
@ -75,12 +76,16 @@ namespace GreatHomeChildcare
{
byte[] pic_in;
Bitmap snapshot = new Bitmap(pictureBox1.Image);
try
{
Image image = (Image)snapshot;
ImageConverter _imageConverter = new ImageConverter();
pic_in = (byte[])_imageConverter.ConvertTo(snapshot, typeof(byte[]));
} catch(Exception ex)
using (var stream = new MemoryStream())
{
snapshot.Save(stream, ImageFormat.Png);
pic_in = stream.ToArray();
}
}
catch (Exception ex)
{
MessageBox.Show("Unable to picture. Try again.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
@ -89,14 +94,15 @@ namespace GreatHomeChildcare
{
child.id = child.id;
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show("This child has not been created yet. Save the child first and then come back.", "Great Home Childcare", MessageBoxButtons.OK, MessageBoxIcon.None);
return;
}
child.photo = pic_in;
SqliteDataAccess.AddWebCamPhoto(child);
SqliteDataAccess.UpdateChild(child);
isCameraRunning = false;
Close();
}
else

View File

@ -117,7 +117,7 @@ namespace GreatHomeChildcare
cnn.Execute(strQuery, new
{
_id = child.id,
_photo = child.photo
_photo = child.photo ?? null
});
}
}

View File

@ -174,13 +174,18 @@ namespace GreatHomeChildcare
int child_id = frmAdminForm.child_id;
SnapShotWin openWebCam = new SnapShotWin(child_id);
openWebCam.Show();
photoPictureBox.Tag = CUSTOM_PIC_TAG;
return;
//TED: Be sure you set this somewhere along the way
//after you wrangle the damn camera.
}
public void changeImageFromCam()
{
photoPictureBox.Image = ImageWrangler.ByteArrayToImage(child.photo);
photoPictureBox.Tag = CUSTOM_PIC_TAG;
MessageBox.Show("Tag has been changed to Custom.");
}
/* On click of the button, open a file picker dialog box
* for the user to browse/choose a picture.