private void openButton_Click(object sender, RoutedEventArgs e) { var dlg = new OpenFileDialog(); if (dlg.ShowDialog(this).Value) { try { if (new FileInfo(dlg.FileName).Extension.ToLower() == ".bmpc") { var image = new ImageBMPC(dlg.FileName, false, null); var writable = new WriteableBitmap(image.Size.Width, image.Size.Height, 96, 96, PixelFormats.Bgra32, null); int stride = (image.Size.Width * 32 + 7) / 8; // Flip RB Color bits var data = new byte[image.Mipmaps[0].Data.LongLength]; image.Mipmaps[0].Data.CopyTo(data, 0); for (int i2 = 0; i2 != data.Length; i2 += 4) { byte c = data[i2]; data[i2] = data[i2+2]; data[i2+2] = c; } writable.WritePixels(new Int32Rect(0, 0, image.Size.Width, image.Size.Height), data, stride, 0); dstImage.Source = writable; } else { // Load binary data var bitmap = new BitmapImage(new Uri(dlg.FileName, UriKind.Absolute)); int stride = (bitmap.PixelWidth * bitmap.Format.BitsPerPixel + 7) / 8; srcData = new byte[bitmap.PixelWidth * stride]; dstData = new byte[bitmap.PixelWidth * stride]; bitmap.CopyPixels(srcData, stride, 0); bitmap.CopyPixels(dstData, stride, 0); // Get image atributes var ext = new FileInfo(dlg.FileName).Extension.ToLower(); width = bitmap.PixelWidth; height = bitmap.PixelHeight; // Display images var w = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96, PixelFormats.Bgra32, null); w.WritePixels(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), srcData, stride, 0); dstImage.Source = w; srcImage.Source = bitmap; processesImage(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public static void Save(byte[] inData, int width, int height, Stream outStream, ImageFormats imageFormat, ImageSavedCallbackMethod imageSavedCallback) { switch (imageFormat) { #if !NaCl && !XNA && !VITA && !WP8 case ImageFormats.BMPC: ImageBMPC.Save(inData, width, height, outStream, imageSavedCallback); break; #endif #if WINRT case ImageFormats.PNG: ImagePNG.Save(inData, width, height, outStream, imageSavedCallback); break; #endif default: Debug.ThrowError("Image", string.Format("Unsuported format: ", imageFormat)); break; } }