コード例 #1
0
        public static ImageSource RetriveImage(string imagePath)
        {
            Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imagePath);

            switch (imagePath.Substring(imagePath.Length - 3))
            {
            case "jpg":
            {
                JpegBitmapDecoder jpegBitmapDecoder = new JpegBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(jpegBitmapDecoder.Frames[0]);
            }

            case "bmp":
            {
                BmpBitmapDecoder bmpBitmapDecoder = new BmpBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(bmpBitmapDecoder.Frames[0]);
            }

            case "png":
            {
                PngBitmapDecoder pngBitmapDecoder = new PngBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(pngBitmapDecoder.Frames[0]);
            }

            case "ico":
            {
                IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(iconBitmapDecoder.Frames[0]);
            }

            default:
                return(null);
            }
        }
コード例 #2
0
        //to embed image into dll
        public System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)
        {
            Stream stream  = this.GetType().Assembly.GetManifestResourceStream(embeddedPath);
            var    decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

            return(decoder.Frames[0]);
        }
コード例 #3
0
ファイル: ImageResouce.cs プロジェクト: YujunA/PresenterWS
        public static BitmapDecoder CreateBitmapDecoder(BitmapEncodingMode mode, Stream fs, BitmapCreateOptions createOpt, BitmapCacheOption cacheOpt)
        {
            BitmapDecoder e = null;

            switch (mode)
            {
            case BitmapEncodingMode.Bmp:
                e = new BmpBitmapDecoder(fs, createOpt, cacheOpt);
                break;

            case BitmapEncodingMode.Gif:
                e = new GifBitmapDecoder(fs, createOpt, cacheOpt);
                break;

            case BitmapEncodingMode.Jpeg:
                e = new JpegBitmapDecoder(fs, BitmapCreateOptions.None, BitmapCacheOption.Default);
                break;

            case BitmapEncodingMode.Png:
                e = new PngBitmapDecoder(fs, createOpt, cacheOpt);
                break;

            case BitmapEncodingMode.Tiff:
                e = new TiffBitmapDecoder(fs, createOpt, cacheOpt);
                break;

            case BitmapEncodingMode.Wmp:
                e = new WmpBitmapDecoder(fs, createOpt, cacheOpt);
                break;
            }
            return(e);
        }
コード例 #4
0
ファイル: Worker.cs プロジェクト: DianaStefanut/DATC-2017
        private BitmapSource ResizeImage(BitmapSource pSource, double pNewWidth)
        {
            //scale image
            double            r          = pNewWidth / pSource.Width;
            ScaleTransform    tr         = new ScaleTransform(r, r);
            TransformedBitmap scalledImg = new TransformedBitmap(pSource, tr);

            //write to memory
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            MemoryStream     stream  = new MemoryStream();

            encoder.Frames.Add(BitmapFrame.Create(scalledImg as BitmapSource));
            encoder.Save(stream);
            stream.Seek(0, SeekOrigin.Begin);

            //read back resized image
            BmpBitmapDecoder decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
            BitmapSource     img     = decoder.Frames[0];

            stream.Close();
            stream.Dispose();
            if (img.CanFreeze)
            {
                img.Freeze();
            }

            return(img);
        }
コード例 #5
0
     void OnDeserialized(StreamingContext sc)
     {
         if (imageArray != null)
         {
             MemoryStream     stream  = new MemoryStream(imageArray);
             BmpBitmapDecoder decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
             imageSource = decoder.Frames[0];
             imageArray  = null;
         }
         if (imageIndices == null)
         {
             imageIndices = new int[] { 0, 0, 0, 0 }
         }
         ;
         if (imageSource == null)
         {
             imageTransformMatrix = Matrix.Identity;
         }
         if (imageSource == null)
         {
             imageTiled = false;
         }
         if (String.IsNullOrEmpty(backColorString))
         {
             backColorString = "DarkGray";
         }
     }
 }
コード例 #6
0
        public static void Sample(string ResultsFileName, string GifFileName, int X, int Y)
        {
            var    sb      = new StringBuilder();
            string path    = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            string inFile  = Path.Combine(path, "..", "..", "..", "..", GifFileName);
            string outFile = Path.Combine(path, "Data");

            if (!Directory.Exists(outFile))
            {
                Directory.CreateDirectory(outFile);
            }
            outFile = Path.Combine(outFile, (ResultsFileName ?? "").Trim() + ".txt");

            var imageStreamSource = new FileStream(inFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            //var decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            var decoder = new BmpBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            var palette = decoder.Palette;

            using (var img = Bitmap.FromFile(inFile, true) as Bitmap)
            {
                FrameDimension dimension  = new FrameDimension(img.FrameDimensionsList[0]);
                int            frameCount = img.GetFrameCount(dimension);
                for (int i = 0; i < frameCount; i++)
                {
                    img.SelectActiveFrame(dimension, i);
                    var col = img.GetPixel(X, Y);
                    sb.AppendLine(GetRRGGBB(col));
                }
            }
            File.WriteAllText(outFile, sb.ToString());
        }
コード例 #7
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var bmp_info = info as BmpMetaData;

            if (bmp_info != null && EnableExtensions && file.AsStream.CanSeek)
            {
                foreach (var ext in m_extensions)
                {
                    try
                    {
                        var image = ext.Read(file, bmp_info);
                        if (null != image)
                        {
                            return(image);
                        }
                    }
                    catch (System.Exception X)
                    {
                        System.Diagnostics.Trace.WriteLine(X.Message, ext.ToString());
                    }
                    file.Position = 0;
                }
            }
            var decoder = new BmpBitmapDecoder(file.AsStream,
                                               BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapSource frame = decoder.Frames.First();

            frame.Freeze();
            return(new ImageData(frame, info));
        }
コード例 #8
0
        private static ImageSource GetEmbeddedBmp(System.Reflection.Assembly app, string imageName)
        {
            var file   = app.GetManifestResourceStream(imageName);
            var source = BmpBitmapDecoder.Create(file, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

            return(source.Frames[0]);
        }
コード例 #9
0
ファイル: ImageALP.cs プロジェクト: zxc120/GARbro
        public ImageData ReadBmp(IBinaryStream file, BmpMetaData info, byte[] alpha, int alp_stride)
        {
            var decoder = new BmpBitmapDecoder(file.AsStream,
                                               BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapSource bitmap = decoder.Frames[0];

            bitmap = new FormatConvertedBitmap(bitmap, PixelFormats.Bgr32, null, 0);
            int dst_stride = (int)info.Width * 4;
            var pixels     = new byte[(int)info.Height * dst_stride];

            bitmap.CopyPixels(pixels, dst_stride, 0);
            int dst = 0;
            int src = 0;

            for (int y = (int)info.Height; y > 0; --y)
            {
                int a_src = src;
                for (int x = 3; x < dst_stride; x += 4)
                {
                    pixels[dst + x] = alpha[a_src++];
                }
                dst += dst_stride;
                src += alp_stride;
            }
            return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels, dst_stride));
        }
コード例 #10
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (!values[0].GetType().Equals(typeof(Mat)))
            {
                return(null);
            }

            Mat imageSource = (Mat)values[0];

            if ((imageSource == null) || (imageSource.Width == 0) || (imageSource.Height == 0))
            {
                return(null);
            }

            Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(imageSource);

            using (Stream stream = new MemoryStream())
            {
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                stream.Seek(0, SeekOrigin.Begin);
                BitmapDecoder bdc = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

                return(bdc.Frames[0]);
            }
        }
コード例 #11
0
ファイル: ImageGCP.cs プロジェクト: zxc120/GARbro
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (GcpMetaData)info;

            stream.Position = 12;
            var reader = new CmpReader(stream.AsStream, meta.PackedSize, meta.DataSize);

            reader.Unpack();
            // 24bpp bitmaps have non-standard stride
            if (24 == meta.BPP && 0 != (meta.Width & 3) &&
                (meta.Height * meta.Width * 3 + 54) == meta.DataSize)
            {
                int stride = (int)meta.Width * 3;
                var pixels = new byte[stride * (int)meta.Height];
                Buffer.BlockCopy(reader.Data, 54, pixels, 0, pixels.Length);
                return(ImageData.CreateFlipped(meta, PixelFormats.Bgr24, null, pixels, stride));
            }
            using (var bmp = new MemoryStream(reader.Data))
            {
                var decoder = new BmpBitmapDecoder(bmp,
                                                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                BitmapSource frame = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }
コード例 #12
0
 public Imagen(Stream stm, string ext)
 {
     InitializeComponent();
     this.ext     = ext;
     img          = new Image();
     mem          = (MemoryStream)stm;
     mem.Position = 0;
     if (ext == "JPG" || ext == "jpg")
     {
         JpegBitmapDecoder decoder = new JpegBitmapDecoder(mem, BitmapCreateOptions.None, BitmapCacheOption.Default);
         BitmapSource      bmpsrc  = decoder.Frames[0];
         img.Source  = bmpsrc;
         img.Stretch = Stretch.Fill;
     }
     else if (ext == "PNG" || ext == "png")
     {
         PngBitmapDecoder decoder = new PngBitmapDecoder(mem, BitmapCreateOptions.None, BitmapCacheOption.Default);
         BitmapSource     bmpsrc  = decoder.Frames[0];
         img.Source  = bmpsrc;
         img.Stretch = Stretch.Fill;
     }
     else if (ext == "BMP" || ext == "bmp")
     {
         BmpBitmapDecoder decoder = new BmpBitmapDecoder(mem, BitmapCreateOptions.None, BitmapCacheOption.Default);
         BitmapSource     bmpsrc  = decoder.Frames[0];
         img.Source  = bmpsrc;
         img.Stretch = Stretch.Fill;
     }
     exito = true;
 }
コード例 #13
0
ファイル: ImageBMP.cs プロジェクト: tenyuhuang/GARbro
        public override ImageData Read(Stream file, ImageMetaData info)
        {
            var decoder = new BmpBitmapDecoder(file,
                                               BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            BitmapSource frame = decoder.Frames.First();

            frame.Freeze();
            return(new ImageData(frame, info));
        }
コード例 #14
0
ファイル: ImageGDT.cs プロジェクト: zxc120/GARbro
 BitmapSource ReadBitmapSource(IBinaryStream file, GdtMetaData info)
 {
     using (var bmp = new StreamRegion(file.AsStream, info.BitmapOffset, true))
     {
         var decoder = new BmpBitmapDecoder(bmp,
                                            BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
         return(decoder.Frames[0]);
     }
 }
コード例 #15
0
        private static BitmapSource LoadBmpImage(string fileName, bool inMemory)
        {
            BitmapDecoder decoder;

            using (var stream = LoadStream(fileName, inMemory))
            {
                decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
            }
            return(decoder.Frames[0]);
        }
コード例 #16
0
 public static ImageSource ConvertImageToImageSource(Image image)
 {
     using (Stream str = new MemoryStream())
     {
         image.Save(str, System.Drawing.Imaging.ImageFormat.Bmp);
         str.Seek(0, SeekOrigin.Begin);
         BitmapDecoder bdc = new BmpBitmapDecoder(str, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
         return(bdc.Frames[0]);
     }
 }
コード例 #17
0
ファイル: MainWindow.xaml.cs プロジェクト: ppervink/gftl
        private string GetCFormattedJumbotronBitmapData(string bmpPath)
        {
            const int BitsPerPixel = PixelSize * 8;
            const int stride       = JumbotronWidth * PixelSize;
            const int size         = JumbotronHeight * stride;

            var decoder = new BmpBitmapDecoder(File.OpenRead(bmpPath), BitmapCreateOptions.None, BitmapCacheOption.None);

            var frame = decoder.Frames.Count != 1 ? null : decoder.Frames[0];

            if (frame is null ||
                frame.PixelHeight != JumbotronHeight ||
                frame.PixelWidth != JumbotronWidth ||
                frame.Format.BitsPerPixel != BitsPerPixel)
            {
                throw new FormatException($"Expected a single frame {JumbotronWidth}px by {JumbotronHeight}px bitmap (.bmp) with {BitsPerPixel} bits per pixel.");
            }

            var builder = new StringBuilder("{" + Environment.NewLine + "\t");

            var pData  = Marshal.AllocHGlobal(size);
            var colors = EnumeratePixelData(pData).GetEnumerator();

            try
            {
                frame.CopyPixels(Int32Rect.Empty, pData, size, stride);

                var more = true;
                for (int y = 0, offset = 0; y < JumbotronHeight && more; y++)
                {
                    for (int x = 0; x < JumbotronWidth; x++, offset += PixelSize)
                    {
                        more = colors.MoveNext();
                        if (!more)
                        {
                            break;
                        }

                        var color = colors.Current;
                        builder.Append(color);
                        builder.Append(x == JumbotronWidth - 1 ? "," + Environment.NewLine + "\t" : ", ");
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pData);
                colors.Dispose();
            }

            var result = builder.ToString().TrimEnd(',', '\t') + "}";

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// <c>Bitmap</c> to <c>BitmapSource</c> conversion method in order to show the edited image at the main window.
        /// </summary>
        /// <remarks>Extension method.</remarks>
        public static BitmapFrame BitmapToBitmapSource(this Bitmap bitmap)
        {
            // Convert Bitmap to BitmapImage
            MemoryStream str = new MemoryStream();

            bitmap.Save(str, ImageFormat.Bmp);
            str.Seek(0, SeekOrigin.Begin);
            BmpBitmapDecoder bdc = new BmpBitmapDecoder(str, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

            return(bdc.Frames[0]);
        }
コード例 #19
0
        //クリップボードの画像取得してリストに追加
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MyBitmaps.Clear();

            var data = Clipboard.GetDataObject();
            var neko = data.GetFormats();

            byte[]       pixels;
            BitmapSource bmp;

            bmp = Clipboard.GetImage();
            MyBitmaps.Add(new MyBitmapSource(bmp, "GetImage()"));
            pixels = GetPixels(bmp);

            bmp = data.GetData("Bitmap") as BitmapSource;
            MyBitmaps.Add(new MyBitmapSource(bmp, "GetData\"Bitmap\""));

            bmp = data.GetData("System.Windows.Media.Imaging.BitmapSource") as BitmapSource;
            MyBitmaps.Add(new MyBitmapSource(bmp, "GetData\"BitmapSource\""));

            if (bmp == null)
            {
                return;
            }
            bmp = new FormatConvertedBitmap(Clipboard.GetImage(), PixelFormats.Bgr32, null, 0);
            MyBitmaps.Add(new MyBitmapSource(bmp, "FormatConvertedBitmapでBgr32"));

            var encoder = new BmpBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(Clipboard.GetImage()));
            using (var stream = new System.IO.MemoryStream())
            {
                encoder.Save(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                var decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                bmp = decoder.Frames[0];
            }
            MyBitmaps.Add(new MyBitmapSource(bmp, "BmpBitmapEncoderDecoder"));

            var pngEncoder = new PngBitmapEncoder();

            pngEncoder.Frames.Add(BitmapFrame.Create(Clipboard.GetImage()));
            using (var stream = new System.IO.MemoryStream())
            {
                pngEncoder.Save(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                bmp = decoder.Frames[0];
            }
            MyBitmaps.Add(new MyBitmapSource(bmp, "PngBitmapEncoderDecoder"));

            //System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
        }
コード例 #20
0
        /// <summary>
        /// Load an image from file.
        /// </summary>
        /// <param name="filename">Absolute path to image to load, incl. extension</param>
        /// <returns>Bitmap instance, or null if loading failed</returns>
        public static BitmapSource LoadImageFromFile(string filename)
        {
            if (filename == null)
            {
                return(null);
            }
            if (!File.Exists(filename))
            {
                return(null);
            }

            string ext = Path.GetExtension(filename).ToLower();

            BitmapSource bitmap = null;

            try
            {
                using (Stream in_strm = File.OpenRead(filename))
                {
                    BitmapCreateOptions cr_option = BitmapCreateOptions.PreservePixelFormat;
                    BitmapCacheOption   ca_option = BitmapCacheOption.OnLoad;
                    BitmapDecoder       dec       = null;
                    switch (ext)
                    {
                    case ".bmp":  dec = new BmpBitmapDecoder(in_strm, cr_option, ca_option); break;

                    case ".gif":  dec = new GifBitmapDecoder(in_strm, cr_option, ca_option); break;

                    case ".jpeg": dec = new JpegBitmapDecoder(in_strm, cr_option, ca_option); break;

                    case ".jpg":  dec = new JpegBitmapDecoder(in_strm, cr_option, ca_option); break;

                    case ".png":  dec = new PngBitmapDecoder(in_strm, cr_option, ca_option); break;

                    case ".tiff": dec = new TiffBitmapDecoder(in_strm, cr_option, ca_option); break;
                    }
                    if (dec == null)
                    {
                        Log.Error("No suitable encoder found for file '{0}'", filename);
                        return(null);
                    }

                    bitmap = dec.Frames[0];
                }
            }
            catch (Exception exc)
            {
                Log.Error("Error loading file '{0}': {1}", filename, exc);
                bitmap = null;
            }

            return(bitmap);
        }
コード例 #21
0
        private void DrawContent()
        {
            pnlContent.Children.Clear();

            if (Clipboard.ContainsText())
            {
                // we have some text in the clipboard.
                TextBox tb = new TextBox();
                tb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                tb.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
                tb.Text         = Clipboard.GetText();
                tb.IsReadOnly   = true;
                tb.TextWrapping = TextWrapping.NoWrap;
                pnlContent.Children.Add(tb);
            }
            else if (Clipboard.ContainsFileDropList())
            {
                // we have a file drop list in the clipboard
                ListBox lb = new ListBox();
                lb.ItemsSource = Clipboard.GetFileDropList();
                pnlContent.Children.Add(lb);
            }
            else if (Clipboard.ContainsImage())
            {
                // Because of a known issue in WPF,
                // we have to use a workaround to get correct
                // image that can be displayed.
                // The image have to be saved to a stream and then
                // read out to workaround the issue.
                MemoryStream     ms  = new MemoryStream();
                BmpBitmapEncoder enc = new BmpBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(Clipboard.GetImage()));
                enc.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);

                BmpBitmapDecoder dec = new BmpBitmapDecoder(ms,
                                                            BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

                Image img = new Image();
                img.Stretch = Stretch.Uniform;
                img.Source  = dec.Frames[0];
                pnlContent.Children.Add(img);
            }
            else
            {
                Label lb = new Label();
                lb.Content = "The type of the data in the clipboard is not supported by this sample.";
                pnlContent.Children.Add(lb);
            }
        }
コード例 #22
0
        Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            try
            {
                Exporter.Instance.settings = new Settings(SaveFormat.ascii, ElementsExportRange.OnlyVisibleOnes, true, true,
                                                          false, false,
                                                          false, 0, 101, 1, 100, 2 /*purgeWrite*/, 8, 7, 4);

                string      str           = "OpenFOAM Exporter";
                RibbonPanel panel         = application.CreateRibbonPanel(str);
                string      directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                string assemblyname = typeof(OpenFOAMExporterUI).Assembly.GetName().Name;
                string dllName      = directoryName + @"\" + assemblyname + ".dll";

                PushButtonData setupData   = new PushButtonData("OpenFOAM Simulate", "Simulate", dllName, "BIM.OpenFOAMExport.OpenFOAMSimulateCommand");
                PushButton     setupButton = panel.AddItem(setupData) as PushButton;
                using (Stream xstr = new MemoryStream())
                {
                    BIM.Properties.Resources.logo_64.Save(xstr, System.Drawing.Imaging.ImageFormat.Bmp);
                    xstr.Seek(0, SeekOrigin.Begin);
                    BitmapDecoder bdc = new BmpBitmapDecoder(xstr, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    setupButton.LargeImage = bdc.Frames[0];
                }
                setupButton.ToolTip         = "The OpenFOAM Exporter for Revit is designed to produce a stereolithography file (STL) of your building model and a OpenFOAM-Config.";
                setupButton.LongDescription = "The OpenFOAM Exporter for the Autodesk Revit Platform is a project designed to create an STL file from a 3D building information model for OpenFOAM with a Config-File that includes the boundary conditions for airflow simulation.";
                ContextualHelp help = new ContextualHelp(ContextualHelpType.ChmFile, directoryName + @"\Resources\ADSKSTLExporterHelp.htm");
                setupButton.SetContextualHelp(help);

                PushButtonData data   = new PushButtonData("OpenFOAM Exporter settings", "Settings", dllName, "BIM.OpenFOAMExport.OpenFOAMExportCommand");
                PushButton     button = panel.AddItem(data) as PushButton;
                using (Stream xstr = new MemoryStream())
                {
                    BIM.Properties.Resources.setupIcon.Save(xstr, System.Drawing.Imaging.ImageFormat.Bmp);
                    xstr.Seek(0, SeekOrigin.Begin);
                    BitmapDecoder bdc = new BmpBitmapDecoder(xstr, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    button.LargeImage = bdc.Frames[0];
                }
                button.ToolTip         = "The OpenFOAM Exporter for Revit is designed to produce a stereolithography file (STL) of your building model and a OpenFOAM-Config.";
                button.LongDescription = "The OpenFOAM Exporter for the Autodesk Revit Platform is a project designed to create an STL file from a 3D building information model for OpenFOAM with a Config-File that includes the boundary conditions for airflow simulation.";
                button.SetContextualHelp(help);

                return(Result.Succeeded);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString(), "OpenFOAM Exporter for Revit");
                return(Result.Failed);
            }
        }
コード例 #23
0
        Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            try
            {
                //set default settings
                Exporter.Instance.settings = new(
                    SaveFormat.ascii,
                    ElementsExportRange.OnlyVisibleOnes,
                    true,
                    false,
                    false,
                    false,
                    0,
                    101,
                    1,
                    100,
                    2 /*purgeWrite*/,
                    8,
                    7,
                    4
                    );

                string      appName      = "OpenFOAM Interface";
                RibbonPanel panel        = application.CreateRibbonPanel(appName);
                string      dirName      = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string      assemblyname = typeof(OpenFOAMInterfaceApp).Assembly.GetName().Name;
                string      dllName      = dirName + @"\" + assemblyname + ".dll";

                PushButtonData simBtnData     = new("OpenFOAM Simulate", "Simulate", dllName, "OpenFOAMInterface.BIM.OpenFOAMSimulateCommand");
                PushButton     simulateButton = panel.AddItem(simBtnData) as PushButton;
                using (Stream xstr = new MemoryStream())
                {
                    Properties.Resources.openfoaminterface.Save(xstr, System.Drawing.Imaging.ImageFormat.Bmp);
                    xstr.Seek(0, SeekOrigin.Begin);
                    BitmapDecoder bdc = new BmpBitmapDecoder(xstr, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                    simulateButton.LargeImage = bdc.Frames[0];
                }
                simulateButton.ToolTip         = "The OpenFOAM Interface for Revit is designed to produce a stereolithography file (STL) of your building model and a OpenFOAM-Config.";
                simulateButton.LongDescription = "The OpenFOAM Iterface for Autodesk Revit is a project designed to create an STL file from a 3D building information model for OpenFOAM with a Config-File that includes the boundary conditions for airflow simulations.";
                ContextualHelp help = new(ContextualHelpType.ChmFile, dirName + @"\Resources\OpenFoamInterfaceHelp.html");
                simulateButton.SetContextualHelp(help);

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                OpenFOAMDialogManager.ShowDialogException(e);
                return(Result.Failed);
            }
        }
コード例 #24
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Bitmap bmp = value as Bitmap;

            if (bmp == null)
            {
                return(null);
            }
            using (Stream str = new MemoryStream()) {
                bmp.Save(str, System.Drawing.Imaging.ImageFormat.Bmp);
                str.Seek(0, SeekOrigin.Begin);
                BitmapDecoder bdc = new BmpBitmapDecoder(str, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                return(bdc.Frames[0]);
            }
        }
コード例 #25
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta   = (TriMetaData)info;
            var output = new byte[meta.UnpackedSize];

            file.Position = 8;
            Unpack(file, output);
            using (var bmp = new BinMemoryStream(output, file.Name))
            {
                var decoder = new BmpBitmapDecoder(bmp, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                var frame   = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }
コード例 #26
0
        private BitmapSource GetClipboardImage3()
        {
            BitmapSource source  = Clipboard.GetImage();
            var          encoder = new BmpBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(source));
            using (var stream = new System.IO.MemoryStream())
            {
                encoder.Save(stream);
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                var decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                source = decoder.Frames[0];
            }
            return(source);
        }
コード例 #27
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!value.GetType().Equals(typeof(Mat)))
            {
                return(null);
            }

            Mat imageSource = value as Mat;

            if ((imageSource == null) || (imageSource.Width == 0) || (imageSource.Height == 0))
            {
                return(null);
            }

            int width  = 512;
            int height = 300;

            double minVal, maxVal;

            Cv2.MinMaxLoc(imageSource, out minVal, out maxVal);
            imageSource = imageSource * (maxVal != 0 ? height / maxVal : 0.0);

            Mat histogram = new Mat(new OpenCvSharp.Size(width, height), MatType.CV_8UC3, Scalar.All(255));

            int[]  histogramSize = { 256 };
            Scalar color         = Scalar.All(100);

            for (int i = 0; i < 256; ++i)
            {
                int binWidth = (int)((double)width / 256);
                histogram.Rectangle(
                    new OpenCvSharp.Point(i * binWidth, histogram.Rows - (int)(imageSource.Get <float>(i))),
                    new OpenCvSharp.Point((i + 1) * binWidth, histogram.Rows),
                    color,
                    -1);
            }

            Bitmap bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(histogram);

            using (Stream stream = new MemoryStream())
            {
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                stream.Seek(0, SeekOrigin.Begin);
                BitmapDecoder bdc = new BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

                return(bdc.Frames[0]);
            }
        }
コード例 #28
0
        private void OpenImg(object sender, RoutedEventArgs e)
        {
            var openFile = new OpenFileDialog();

            openFile.Filter           = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG;)|*.BMP;*.JPG;*.GIF;*.PNG;";
            openFile.RestoreDirectory = true;
            if (openFile.ShowDialog() == true)
            {
                dynamic decoder = null;
                try
                {
                    var streamSource = new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    switch (new FileInfo(openFile.FileName).Extension)
                    {
                    case ".jpg":
                        decoder = new JpegBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".png":
                        decoder = new PngBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".bmp":
                        decoder = new BmpBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".gif":
                        decoder = new GifBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    }
                    uploadedImg.Source = decoder.Frames[0];
                }
                catch (Exception err)
                {
                    ShowMessageBox(err.Message.ToString(), "Error");
                    return;
                }
                imagePath.Text = openFile.FileName;
                keyPath.Text   = null;
                SetParams();
                DrawSettings();
                if (Encryption.currentAlg == 0 && uploadedImg.Source != null)
                {
                    TranspositionAlg.SetKey(Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource));
                }
                decrypted = false;
            }
        }
コード例 #29
0
ファイル: ImageMGO.cs プロジェクト: zxc120/GARbro
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var meta = (MgoMetaData)info;

            file.Position = 12;
            using (var lzss = new PackedStream <LzssDecompressor> (file.AsStream, true))
            {
                var header = new byte[meta.BmpOffset];
                lzss.Read(header, 0, header.Length);
                var decoder = new BmpBitmapDecoder(lzss,
                                                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                var frame = decoder.Frames[0];
                frame.Freeze();
                return(new ImageData(frame, info));
            }
        }
コード例 #30
0
        private void LoadImagesIntoXML(string xml)
        {
            byte[] imageArr = Convert.FromBase64String(xml);
            System.Windows.Controls.Image img = new System.Windows.Controls.Image();

            MemoryStream     stream  = new MemoryStream(imageArr);
            BmpBitmapDecoder decoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);

            img.Source  = decoder.Frames[0];
            img.Stretch = Stretch.None;

            Paragraph p = new Paragraph();

            p.Inlines.Add(img);
            rtbPad.Document.Blocks.Add(p);
        }