Images working

This commit is contained in:
Matthew Burke
2023-07-27 18:59:51 -04:00
parent 1b65e9bb83
commit 09d86b86c2
7 changed files with 300 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.DataObjects
{
class Attachment
{
APICredentials Credentials;
PWImage image;
string Token;
public Attachment(APICredentials credentials, PWImage pwImage, string token)
{
Credentials = credentials;
image = pwImage;
Token = token;
}
public string ToJsonString()
{
return "\"{" + Credentials.BuildJsonBodyContents() +
",'UserNum':'API'," +
"'AttToken':'" + Token.Replace("\"", "") + "'," +
"'FileName':'" + image.ShortFileName() + "'," +
"'ContentType':'_1'," +
"'ThumbExists':'1'," +
"'ZoomExists':'1'," +
"'FileDate':''," +
"'Base64FileContents':'" + image.GetBase64String() + "',\n" +
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
}
}
}
+105
View File
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Drawing;
using System.IO;
namespace PWAPPv2.Source.DataObjects
{
public class PWImage
{
private string ImagePath;
private BitmapImage bitmap;
//private Bitmap bmp;
//private Bitmap thumb;
//private Bitmap zoom;
public PWImage(string path)
{
ImagePath = path;
bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(@ImagePath);
bitmap.DecodePixelWidth = 100;
bitmap.EndInit();
//bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
//thumb = resize(bmp, 50, 50);
//zoom = resize(bmp, bmp.Width, bmp.Height);
}
public string GetPath()
{
return ImagePath;
}
public BitmapImage GetBitmapImage()
{
return bitmap;
}
public string GetBase64String()
{
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
return Convert.ToBase64String(imageBytes);
}
}
}
public string GetBase64ThumbString()
{
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
{
Image thumb = resize(image, new Size(50, 50));
using (MemoryStream m = new MemoryStream())
{
thumb.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
return Convert.ToBase64String(imageBytes);
}
}
}
public string GetBase64ZoomString()
{
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
{
Image zoom = resize(image, new Size(image.Width + 800, image.Height + 800));
using (MemoryStream m = new MemoryStream())
{
zoom.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
return Convert.ToBase64String(imageBytes);
}
}
}
private Image resize(Image toResize, Size size)
{
return new Bitmap(toResize, size);
}
public string ShortFileName()
{
return ImagePath.Substring(ImagePath.LastIndexOf("\\") + 1);
}
}
}
+10 -3
View File
@@ -20,7 +20,9 @@ namespace PWAPPv2.Source.DataObjects
RichTextBox RemarksBox;
CheckBox ContactBox;
public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox)
bool Attachments;
public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox, bool attachments)
{
ApiCredentials = apiCredentials;
PatientData = patient;
@@ -29,6 +31,7 @@ namespace PWAPPv2.Source.DataObjects
ReferFrom = referFrom;
RemarksBox = remarksBox;
ContactBox = contactBox;
Attachments = attachments;
}
public string ToJsonString()
@@ -41,7 +44,11 @@ namespace PWAPPv2.Source.DataObjects
{
contact = 1;
}
string attachmentsText = "False";
if (Attachments)
attachmentsText = "True";
try
{
return "\"{" + ApiCredentials.BuildJsonBodyContents() + "," +
@@ -61,7 +68,7 @@ namespace PWAPPv2.Source.DataObjects
"'SubmittedBy':'" + ReferFrom.GetSelectedID() + "'," +
"'ToPracticeId':'" + ReferTo.GetSelectedPracticeID() + "'," +
"'ToDoctorID':'" + ReferTo.GetSelectedDoctorID() + "'," +
"'Attachments':'False'," +
"'Attachments':'" + attachmentsText + "'," +
"'Remarks':'" + RemarksText + "'," +
"'Contact':'" + contact + "'}\"";
}