123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using System;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace Phihong_EVSE_UI_Tool
- {
- public static class Utility
- {
- public const string BG_PARENTFOLDER = @"Background\";
- public const string BG_INITIAL = "0_init.bmp";
- public const string BG_IDLE = "1_idle.bmp";
- public const string BG_VERIFY = "2_verify.bmp";
- public const string BG_VERIFYOK = "3_carChkok.bmp";
- public const string BG_VERIFYFAIL = "4_chkfail.bmp";
- public const string BG_PLUG = "5_plug.bmp";
- public const string BG_PRECHARGE = "6_precharge.bmp";
- public const string BG_CHARGING = "7_charging.bmp";
- public const string BG_COMPLETE = "8_complete.bmp";
- public const string BG_MAINTAIN = "9_fix.bmp";
- public const string ICO_PARENTFOLDER = @"ICO\";
- public const string ICO_LOGO = "10_logo.bmp";
- public const string ICO_NAME = "60.ICO";
- public static readonly string OUTPUT_DIRECTORY = Environment.CurrentDirectory + @"\Output\";
- public static readonly string CUSTOM_DIRECTORY = Environment.CurrentDirectory + @"\CustomTemp\";
- public static void CopyFileFromResource(Uri uriString, string destPath)
- {
- using (var resource = Application.GetResourceStream(uriString).Stream)
- {
- using (var file = new FileStream(destPath, FileMode.Create, FileAccess.Write))
- {
- resource.CopyTo(file);
- }
- }
- }
- public static void LoadImageFromPath(Image imgControl, string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- imgControl.BeginInit();
- imgControl.Source = bitmap;
- imgControl.EndInit();
- }
- public static bool IsBackgroundImageSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth != 800 || bitmap.PixelHeight != 480)
- {
- return false;
- }
- return true;
- }
- public static bool IsIcoImageSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth > 255 || bitmap.PixelHeight > 255)
- {
- return false;
- }
- return true;
- }
- public static bool IsIcoLogoSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth != 186 || bitmap.PixelHeight != 34)
- {
- return false;
- }
- return true;
- }
- public static void ConvertToBitmap565Array(string path, out int width, out int height, out byte[] pixels)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- FormatConvertedBitmap newFormated = new FormatConvertedBitmap();
- newFormated.BeginInit();
- newFormated.Source = bitmap;
- newFormated.DestinationFormat = PixelFormats.Bgr565;
- newFormated.EndInit();
- width = newFormated.PixelWidth;
- height = newFormated.PixelHeight;
- var stride = (newFormated.PixelWidth * newFormated.Format.BitsPerPixel + 7) / 8;
- pixels = new byte[newFormated.PixelHeight * stride];
- newFormated.CopyPixels(pixels, stride, 0);
- for (int i = 0; i < pixels.Length; i += 2)
- {
- byte temp = pixels[i];
- pixels[i] = pixels[i + 1];
- pixels[i + 1] = temp;
- }
- }
- }
- }
|