//------------------------------------------------------------------------------------------------------------------------------------------------------------- public static bool Test(bool writeToFile) { bool success = false; try { ////////////////////////////////// string dir = "C:\\Backups\\Photos_Testing_ImageResizing\\"; string photoPath = dir + "ImageResizeTest1.jpg"; int width = 1999; int height = 1999; MemoryStream ms = null; success = ImageProcessor.ResizeImage(photoPath, width, height, out ms); //_____ Convert this thumbnail image to a memory stream .... if (writeToFile) { byte[] targetBytes = ms.ToArray(); // Finally - write this file back out .... string fileName = dir + "Output_" + DateTimeInformation.GetCurrentDate("number") + "_" + DateTimeInformation.GetCurrentTime() + ".jpg"; //+ ".png"; // Image im = Image.FromStream(ms); // im.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg); FileStream fs = new FileStream(fileName, FileMode.Create); fs.Write(targetBytes, 0, targetBytes.Length); fs.Flush(); fs.Close(); if (ms.Length > 0) { success = true; } } else { if (ms != null && ms.Length > 0) { success = true; } } } catch (Exception ex) { string temp = ex.ToString(); } return(success); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------- public static bool Test(bool writeToFile) { bool success = false; try { ImageProcessorGDI ipGDI = new ImageProcessorGDI(); MemoryStream ms = null; string dir = "C:\\Backups\\Photos_Testing_ImageResizing\\"; string photoPath = dir + "ImageResizeTest1.jpg"; success = ImageProcessorGDI.ResizeImage(photoPath, 1999, 1999, out ms); //_____ Convert this thumbnail image to a memory stream .... if (writeToFile) { Image im = Image.FromStream(ms); // byte[] targetBytes = ms.ToArray(); im.Save(dir + "OutputGDI_" + DateTimeInformation.GetCurrentDate("number") + "_" + DateTimeInformation.GetCurrentTime() + ".jpg", ImageFormat.Jpeg); // Finally - write this file back out .... // FileStream fs = new FileStream(, FileMode.Create); // fs.Write(targetBytes, 0, targetBytes.Length); //fs.Flush(); // fs.Close(); // if (targetBytes.Length > 0) { success = true; // } } else { if (ms != null && ms.Length > 0) { success = true; } } } catch (Exception ex) { Logger.LogError(5, "Problem resulted in crash in ImageProcessorGDI.Test(): " + ex.ToString()); // string temp = ""; } return(success); }
//----------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Generates the log file name. Normally a concatenation of the action and the date and time. /// For error messages, the severity is also prefixed to the log file for easier reading of web related issues /// 19-Nov-2015 - modified so that the directory is not passed in /// </summary> /// <param name="logAction">A description of the action that this log is performing</param> /// <returns>The name of the log file</returns> public static string GenerateLogFileName(string logAction) { // Generate the fileName here based on the action and the current date and time string date = DateTimeInformation.GetCurrentDate(null); string time = DateTimeInformation.GetCurrentTime(); // 8-Oct-2015 - Added the milliseconds so that we can better see what is happening in more complex situations string tempFileName = logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt"; // check to see if this fileName exists already (i.e. there is another log file with the same action for exactly the same second!!! // If this has happened, add the number of milliseconds too if (File.Exists(fileName)) // SimpleIO.FileExists(fileName)) { //tempFileName = logDirectory + "/" + logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt"; { tempFileName = logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt"; } return(tempFileName); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------- public static bool TestOriginal() { bool success = false; try { ////////////////////////////////// string dir = "C:\\Backups\\Photos_Testing_ImageResizing\\"; string photoPath = dir + "ImageResizeTest1.jpg"; int width = 1999; int height = 1999; //BitmapImage bi = new BitmapImage(); //bi.BeginInit(); //bi.UriSource = new Uri(photoPath); //bi.DecodePixelWidth = width; //bi.DecodePixelHeight = height; //bi.EndInit(); //bi = null; FileStream photoStream = new FileStream(photoPath, FileMode.Open); BitmapDecoder photoDecoder = BitmapDecoder.Create( photoStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); BitmapFrame photo = photoDecoder.Frames[0]; TransformedBitmap target = new TransformedBitmap( photo, new ScaleTransform( width / photo.Width * 96 / photo.DpiX, height / photo.Height * 96 / photo.DpiY, 0, 0)); BitmapFrame thumbnail = BitmapFrame.Create(target); //_____ Convert this thumbnail image to a memory stream .... byte[] targetBytes = null; using (MemoryStream memoryStream = new MemoryStream()) { JpegBitmapEncoder targetEncoder = new JpegBitmapEncoder(); // PngBitmapEncoder(); targetEncoder.Frames.Add(thumbnail); targetEncoder.Save(memoryStream); targetBytes = memoryStream.ToArray(); } photoStream.Flush(); photoStream.Close(); // Finally - write this file back out .... FileStream fs = new FileStream(dir + "Output_" + DateTimeInformation.GetCurrentDate("number") + "_" + DateTimeInformation.GetCurrentTime() + ".jpg", FileMode.Create); fs.Write(targetBytes, 0, targetBytes.Length); fs.Flush(); fs.Close(); if (targetBytes.Length > 0) { success = true; } } catch (Exception ex) { string temp = ex.ToString(); } return(success); }