70002328 Import EMF from stream

Article 70002328
Type HowTo
Product Engine
Version 10
Date Added 3/23/2023 12:00:00 AM
Fixed 10.1004.0.1 (3/24/2023 12:00:00 AM)
Submitted by Ze Xiu

Summary

How to import EMF from stream?

Solution

You can do this using vdImageDef object and also have control on the EMFImportPropertiesFlags setting. Try a code like:

                byte[] bytes = null;
                vdImageDef imagedef = new vdImageDef(doc, "My_emf_from_stream");
                MemoryStream EMFmstream = ..... here is the EMF file in a stream ....
                bytes = EMFmstream.ToArray();
                imagedef.InternalSetBytes(new ByteArray(bytes));
                
                doc.Images.AddItem(imagedef);
                vdImage obj = new vdImage();
                obj.SetUnRegisterDocument(doc);
                obj.setDocumentDefaults();
                obj.ImageDefinition = imagedef;
                if (imagedef.Image.IsEMF)
                {
                    obj.ImageScale = imagedef.Image.Width;
                    obj.Draw3DFlag = Draw3DFlagEnum.ExcludeFromList;
                }
                switch (doc.FileProperties.EMFImportProperties)
                {
                    case vdFileProperties.EMFImportPropertiesFlags.AsImage:
                        doc.Model.Entities.AddItem(obj);
                        break;
                    case vdFileProperties.EMFImportPropertiesFlags.AsBlockRef:
                        {
                            VectorDraw.Professional.vdCollections.vdEntities figs = obj.Explode();
                            foreach (VectorDraw.Professional.vdPrimaries.vdFigure fig in figs) doc.Model.Entities.AddItem(fig);
                        }
                        break;
                    case vdFileProperties.EMFImportPropertiesFlags.AsExploded:
                        {
                            VectorDraw.Professional.vdCollections.vdEntities figs = obj.Explode();
                            foreach (VectorDraw.Professional.vdPrimaries.vdFigure fig in figs)
                            {
                                VectorDraw.Professional.vdCollections.vdEntities figs2 = fig.Explode();
                                foreach (VectorDraw.Professional.vdPrimaries.vdFigure fig2 in figs2) doc.Model.Entities.AddItem(fig2);
                            }
                        }
                        break;
                    default:
                        break;
                }
                doc.CommandAction.Zoom("e", null, null);

Send comments on this topic.