zoukankan      html  css  js  c++  java
  • C# CAD 2020 图纸 导出图片

     CAD

    #region 照片提取
            public ImageFormat GetFormat(string filename)
            {
                // If all else fails, let's create a PNG
                // (might also choose to throw an exception)
                var imf = ImageFormat.Png;
                if (filename.Contains("."))
                {
                    // Get the filename's extension (what follows the last ".")
                    string ext = filename.Substring(filename.LastIndexOf(".") + 1);
                    // Get the first three characters of the extension
                    if (ext.Length > 3)
                        ext = ext.Substring(0, 3);
                    // Choose the format based on the extension (in lowercase)
                    switch (ext.ToLower())
                    {
                        case "bmp":
                            imf = ImageFormat.Bmp;
                            break;
    
                        case "gif":
                            imf = ImageFormat.Gif;
                            break;
    
                        case "jpg":
                            imf = ImageFormat.Jpeg;
                            break;
    
                        case "tif":
                            imf = ImageFormat.Tiff;
                            break;
    
                        case "wmf":
                            imf = ImageFormat.Wmf;
                            break;
    
                        default:
                            imf = ImageFormat.Png;
                            break;
                    }
                }
                return imf;
            }
    
            [CommandMethod("CPI")]
            public void CreatePreviewImage()
            {
                if (Document == null) return;
                var ed = Document.Editor;
                // Select the filename and type for our output image
                var pofo = new PromptSaveFileOptions("
    Select image location");
                pofo.Filter =
                  "Bitmap (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|" +
                  "PNG (*.png)|*.png|TIFF (*.tif)|*.tif";
                // Set the default save location to be that of the current drawing
                string fn = Document.Database.Filename;
                if (fn.Contains("."))
                {
                    int extIdx = fn.LastIndexOf(".");
                    if (fn.Substring(extIdx + 1) != "dwt" && fn.Contains("\"))
                    {
                        pofo.InitialDirectory = Path.GetDirectoryName(Document.Database.Filename);
                    }
                }
    
                var pfnr = ed.GetFileNameForSave(pofo);
    
                if (pfnr.Status != PromptStatus.OK) return;
                var outFile = pfnr.StringResult;
    #if NET35
    
    #else
                // Get the size of the document and capture the preview at that size
                var size = Document.Window.DeviceIndependentSize;
                using (var bmp = Document.CapturePreviewImage(Convert.ToUInt32(size.Width), Convert.ToUInt32(size.Height)))
                {
                    // Save the file with the format derived from the filename
                    bmp.Save(outFile, GetFormat(outFile));
                }
    #endif
            }
            #endregion 照片提取
  • 相关阅读:
    集群服务器登录退出出现问题
    TP框架中的Db::name 和 dB::table 以及 db('') 的区别
    TP5中orderRaw用法
    视差滚动 插件
    ThinkPad t480s 电源接口进水了
    file_put_contents failed to open stream: Permission denied in
    Mac 如何安装字体?
    ZipArchive::close(): Failure to create temporary file: Permission denied
    Wifi6 路由器推荐
    名词解释 | Enteric Nervous System | Enteric Neural Crest Cell | ENS | ENCC | 神经系统 | 神经嵴细胞
  • 原文地址:https://www.cnblogs.com/shangdishijiao/p/15166499.html
Copyright © 2011-2022 走看看