public static IntPtr GetHIcon(ImageSource source) { System.Windows.Media.Imaging.BitmapFrame frame = source as System.Windows.Media.Imaging.BitmapFrame; if (frame != null && frame.Decoder.Frames.Count > 0) { frame = frame.Decoder.Frames[0]; int width = frame.PixelWidth; int height = frame.PixelHeight; int stride = width * ((frame.Format.BitsPerPixel + 7) / 8); byte[] bits = new byte[height * stride]; frame.CopyPixels(bits, stride, 0); // pin the bytes in memory (avoids using unsafe context) GCHandle gcHandle = GCHandle.Alloc(bits, GCHandleType.Pinned); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, gcHandle.AddrOfPinnedObject()); IntPtr hIcon = bitmap.GetHicon(); gcHandle.Free(); return(hIcon); } return(IntPtr.Zero); }
public static System.Windows.Media.Imaging.BitmapSource GetBitmapSource(System.Drawing.Bitmap bmp) { System.Windows.Media.Imaging.BitmapFrame bf = null; using (MemoryStream ms = new System.IO.MemoryStream()) { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); bf = System.Windows.Media.Imaging.BitmapFrame.Create(ms, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad); } return(bf); }
public System.UInt16 ExifOrientation() { #region Nota sobre metadatos EXIF /** * The 8 EXIF orientation values are numbered 1 to 8. * * 1 = 0 degrees: the correct orientation, no adjustment is required. * 2 = 0 degrees, mirrored: image has been flipped back-to-front. * 3 = 180 degrees: image is upside down. * 4 = 180 degrees, mirrored: image is upside down and flipped back-to-front. * 5 = 90 degrees: image is on its side. * 6 = 90 degrees, mirrored: image is on its side and flipped back-to-front. * 7 = 270 degrees: image is on its far side. * 8 = 270 degrees, mirrored: image is on its far side and flipped back-to-front. || RotatedRightAndMirroredVertically */ #endregion try { System.Windows.Media.Imaging.BitmapFrame frame = System.Windows.Media.Imaging.BitmapFrame.Create(new System.Uri(Path), System.Windows.Media.Imaging.BitmapCreateOptions.DelayCreation, System.Windows.Media.Imaging.BitmapCacheOption.Default); var bmData = (System.Windows.Media.Imaging.BitmapMetadata)frame.Metadata; if (bmData != null) { object val = bmData.GetQuery("/app1/ifd/exif:{uint=274}"); if (val != null) { System.UInt16 exifrotation = 0; if (System.UInt16.TryParse(val.ToString(), out exifrotation)) { return(exifrotation); } } } return(0); } catch (System.Exception) { return(0); } }
public static void Save(string Output) { System.Windows.Media.Imaging.GifBitmapEncoder G = new System.Windows.Media.Imaging.GifBitmapEncoder(); List <System.IO.FileStream> X = new List <System.IO.FileStream>(); foreach (string Fi in Directory.GetFiles(tempDir, "*.png", SearchOption.TopDirectoryOnly)) { System.IO.FileStream TempStream = new System.IO.FileStream(Fi, System.IO.FileMode.Open); System.Windows.Media.Imaging.BitmapFrame Frame = System.Windows.Media.Imaging.BitmapFrame.Create(TempStream); X.Add(TempStream); G.Frames.Add(Frame); } System.IO.FileStream FS = new System.IO.FileStream(Output, System.IO.FileMode.OpenOrCreate); G.Save(FS); FS.Close(); foreach (System.IO.FileStream St in X) { St.Close(); } }
public static System.Windows.Media.ImageMetadata GetMetaData(System.Windows.Media.Imaging.BitmapFrame frame) { return(frame == null ? null : frame.Metadata); }