Images working
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user