Ejemplo n.º 1
0
        private static void SaveClipboardEmf(Stream stream, ImageFormat format)
        {
            OpenClipboard();

            try
            {
                if (!IsClipboardFormatAvailable(CF_ENHMETAFILE))
                {
                    Failed("No enhanced metafile data available.");
                }

                IntPtr ptr = GetClipboardData(CF_ENHMETAFILE);

                if (ptr == IntPtr.Zero)
                {
                    Failed("Unable to retrieve data from clipboard even through Clipboard previously indicated data exists.");
                }

                var metafile = new Metafile(ptr, true);
                metafile.Save(stream, format);
            }
            finally
            {
                // "An application should call the CloseClipboard function after every successful call to OpenClipboard."
                //   -- http://msdn.microsoft.com/en-us/library/windows/desktop/ms649048(v=vs.85).aspx
                CloseClipboard();
            }
        }
 protected virtual void SaveMetafileToFile(System.Drawing.Imaging.Metafile image, string output)
 {
     using (Stream s = new FileStream(output, FileMode.Create))
     {
         Log.LogMessage("Saving image as jpg to {0}", output);
         image.Save(s, ImageFormat.Jpeg);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a Metafile to specified image format(s).
        /// </summary>
        static void ExportMetafile(System.Drawing.Imaging.Metafile metafile, string baseSheetFileName, Options options)
        {
            if (options.ExportBMP)
            {
                // Build full path to BMP.
                var bmpFileName = String.Format("{0}.bmp", baseSheetFileName);

                // Convert EMF to BMP.
                metafile.Save(bmpFileName, ImageFormat.Bmp);

                Console.WriteLine("Extracted '{0}'.", bmpFileName);
            }

            if (options.ExportJPG)
            {
                // Build full path to JPG.
                var jpgFileName = String.Format("{0}.jpg", baseSheetFileName);

                // Convert EMF to JPG.
                metafile.Save(jpgFileName, ImageFormat.Jpeg);

                Console.WriteLine("Extracted '{0}'.", jpgFileName);
            }

            if (options.ExportPNG)
            {
                // Build full path to PNG.
                var pngFileName = String.Format("{0}.png", baseSheetFileName);

                // Convert EMF to PNG.
                metafile.Save(pngFileName, ImageFormat.Png);

                Console.WriteLine("Extracted '{0}'.", pngFileName);
            }

            if (options.ExportTIF)
            {
                // Build full path to TIF.
                var tifFileName = String.Format("{0}.tif", baseSheetFileName);

                // Convert EMF to TIF.
                metafile.Save(tifFileName, ImageFormat.Tiff);

                Console.WriteLine("Extracted '{0}'.", tifFileName);
            }
        }
Ejemplo n.º 4
0
 public virtual void Save(string filename)
 {
     mMetafile.Save(filename);
 }
Ejemplo n.º 5
0
 void saveAsImageFile()
 {
     if (File.Exists(m_strTreeFile))
     {
         Graphics grfx = CreateGraphics();
         IntPtr ipHdc = grfx.GetHdc();
         string strMetafile = createFileName("emf");
         mf = new Metafile(strMetafile, ipHdc);
         grfx.ReleaseHdc(ipHdc);
         grfx.Dispose();
         Graphics grfxMF = Graphics.FromImage(mf);
         grfxMF.PageUnit = GraphicsUnit.Millimeter;
         grfxMF.PageScale = .01f;
         SolidBrush brush = new SolidBrush(tree.BackgroundColor);
         PointF pf = new PointF(0f, 0f);
         if (Environment.OSVersion.Platform == PlatformID.Win32Windows)
         {   // adjust because Win98 is extra high (for some reason...)
             pf.Y = grfxMF.DpiY / .254f;
         }
         if (tree.TrySmoothing && tree.TryPixelOffset)
             tree.XSize += 6; // adjust for the pixel offset
         grfxMF.FillRectangle(brush, 0, 0, tree.XSize, tree.YSize + (int)pf.Y);
         tree.Draw(grfxMF, tree.LinesColor);
         brush.Dispose();
         grfxMF.Dispose();
         string strFile;
         if (m_bUseBmp)
         {
             strFile = createFileName("bmp");
             mf.Save(strFile, ImageFormat.Bmp);
         }
         if (m_bUseGif)
         {
             strFile = createFileName("gif");
             mf.Save(strFile, ImageFormat.Gif);
         }
         if (m_bUseJpg)
         {
             strFile = createFileName("jpg");
             mf.Save(strFile, ImageFormat.Jpeg);
         }
         if (m_bUsePng)
         {
             strFile = createFileName("png");
             mf.Save(strFile, ImageFormat.Png);
         }
         if (m_bUseTif)
         {
             strFile = createFileName("tif");
             mf.Save(strFile, ImageFormat.Tiff);
         }
         mf.Dispose();
         if (!m_bUseEmf)
             File.Delete(strMetafile);
     }
 }
		void AddPictire(Plan plan, surfacesSurfaceLayerElementsElement innerElement, ref int pictureIndex)
		{
			try
			{
				if (innerElement.picture == null)
					return;

				foreach (var innerPicture in innerElement.picture)
				{
					if (string.IsNullOrEmpty(innerPicture.idx))
						innerPicture.idx = pictureIndex++.ToString();

					var picturesDirectory = GetPicturesDirectory();
					if (picturesDirectory == null)
						continue;
					var directoryInfo = new DirectoryInfo(picturesDirectory + "\\Sample" + innerPicture.idx + "." + innerPicture.ext);
					if (File.Exists(directoryInfo.FullName) == false)
						continue;

					if (innerPicture.ext == "emf")
					{
						var metafile = new Metafile(directoryInfo.FullName);
						innerPicture.ext = "bmp";
						directoryInfo = new DirectoryInfo(picturesDirectory + "\\Sample" + innerPicture.idx + "." + innerPicture.ext);
						metafile.Save(directoryInfo.FullName, ImageFormat.Bmp);
						metafile.Dispose();
					}

					var guid = ServiceFactoryBase.ContentService.AddContent(directoryInfo.FullName);
					var elementRectanglePicture = new ElementRectangle()
					{
						Left = Parse(innerElement.rect[0].left),
						Top = Parse(innerElement.rect[0].top),
						Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
						Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
					};

					if ((elementRectanglePicture.Left == 0) && (elementRectanglePicture.Top == 0) && (elementRectanglePicture.Width == plan.Width) && (elementRectanglePicture.Height == plan.Height))
					{
						plan.BackgroundImageSource = guid;
						plan.BackgroundSourceName = directoryInfo.FullName;
					}
					else
					{
						elementRectanglePicture.BackgroundImageSource = guid;
						elementRectanglePicture.BackgroundSourceName = directoryInfo.FullName;
						plan.ElementRectangles.Add(elementRectanglePicture);
					}
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "ConfigurationConverter.AddPictire");
			}
		}
        void AddPictire(Plan plan, surfacesSurfaceLayerElementsElement innerElement, ref int pictureIndex)
        {
            foreach (var innerPicture in innerElement.picture)
            {
                if (string.IsNullOrEmpty(innerPicture.idx))
                    innerPicture.idx = pictureIndex++.ToString();

                var directoryInfo = new DirectoryInfo(Environment.CurrentDirectory + "\\Pictures\\Sample" + innerPicture.idx + "." + innerPicture.ext);
                if (File.Exists(directoryInfo.FullName) == false)
                    continue;

                if (innerPicture.ext == "emf")
                {
                    var metafile = new Metafile(directoryInfo.FullName);
                    innerPicture.ext = "bmp";
                    directoryInfo = new DirectoryInfo(Environment.CurrentDirectory + "\\Pictures\\Sample" + innerPicture.idx + "." + innerPicture.ext);
                    metafile.Save(directoryInfo.FullName, ImageFormat.Bmp);
                    metafile.Dispose();
                }

                byte[] backgroundPixels = File.ReadAllBytes(directoryInfo.FullName);

                var elementRectanglePicture = new ElementRectangle()
                {
                    Left = Parse(innerElement.rect[0].left),
                    Top = Parse(innerElement.rect[0].top),
                    Height = Parse(innerElement.rect[0].bottom) - Parse(innerElement.rect[0].top),
                    Width = Parse(innerElement.rect[0].right) - Parse(innerElement.rect[0].left),
                    BackgroundPixels = backgroundPixels
                };

                if ((elementRectanglePicture.Left == 0) && (elementRectanglePicture.Top == 0) && (elementRectanglePicture.Width == plan.Width) && (elementRectanglePicture.Height == plan.Height))
                {
                    plan.BackgroundPixels = elementRectanglePicture.BackgroundPixels;
                }
                else
                {
                    plan.ElementRectangles.Add(elementRectanglePicture);
                }
            }
        }