private void StretchForDifferentDpi(IntPtr hwnd, int width, int height, Image masterImage) { Size offset = new Size(masterImage.Width - width, masterImage.Height - height); //The original application of this method assumes that a master image was captured on a machine //set to 96dpi and scales the window size appropriately. However, if a master was actually captured on a //machine that is set to a dpi other than 96, we want to provide the option not to automatically scale the Window. if (_resizeWindowForDpi) { IMasterDimension currentDpi = MasterMetadata.GetDimension("DpiDimension"); int standardDpi = 96; if (currentDpi.GetCurrentValue() != standardDpi.ToString()) { int dpi = int.Parse(currentDpi.GetCurrentValue()); float ratio = (float)dpi / standardDpi; offset.Width = (int)(masterImage.Width * ratio - width + .5); offset.Height = (int)(masterImage.Height * ratio - height + .5); } } if (offset.IsEmpty) { return; } ResizeWindow(hwnd, offset.Width, offset.Height, true); }
/// <summary> /// Retrieve the OSinfo stored in the image /// </summary> /// <param name="image">The image to parse</param> /// <returns>returne a MasterMetadata object containing the description and criteria</returns> public static MasterMetadata MetadataFromImage(Image image) { MasterMetadata retVal = new MasterMetadata(); // Check if the image contains criteria & description List <int> idList = new List <int>(); idList.AddRange(image.PropertyIdList); if (idList.Contains(EXIF_IMAGEINFO)) { // Deserialize Description and Criteria from the image metadata (saved as xmlNode) PropertyItem pi = image.GetPropertyItem(EXIF_IMAGEINFO); // Remove trailing '\0' since it messes up deserialization string serializedInfo = System.Text.UTF8Encoding.UTF8.GetString(pi.Value); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(serializedInfo.Trim('\0'))); XmlReaderSettings readerSettings = new XmlReaderSettings(); memoryStream.Position = 0; XmlReader reader = XmlReader.Create(memoryStream, readerSettings); while (reader.Read()) { string dim = string.Empty; string val = string.Empty; string index = string.Empty; if (reader.Name == "Dim") { dim = reader["name"]; val = reader["value"]; retVal.Description[MasterMetadata.GetDimension(dim)] = val; } if (reader.Name == "Index") { index = reader["name"]; retVal._criteria.Add(MasterMetadata.GetDimension(index)); } } } return(retVal); }