• 使用C#解析XMIND文件格式


     static void Main(string[] args)
            {
                var tempPath = @"c:Temp";
    
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath,true);
                }
                Directory.CreateDirectory(tempPath);
    
                ZipFile.ExtractToDirectory(@"c:	est.xmind", tempPath);
    
                //缩略图地址
                var thumbPath = tempPath + "\Thumbnails\thumbnail.png";
                var targetThumbPath = tempPath + "\Thumbnails\160X120.png";
                var fi=new FileInfo(targetThumbPath);
                if (fi.Exists)
                {
                    fi.IsReadOnly = false;
                    fi.Delete();
                }
                int width;
                int height;
                ThumbImage.GetMicroImage(thumbPath, targetThumbPath, 160, 120, out width, out height);
                Console.WriteLine("缩略图:"+ targetThumbPath);
                Console.WriteLine("预览图:" + thumbPath + " 原图宽:" + width + ",原图高:" + height);
                //附件
                var attachmentsPath = new DirectoryInfo(tempPath + "\attachments");
                var count = 0;
                foreach (var o in attachmentsPath.GetFiles())
                {
                    count++;
                    Console.WriteLine("附件"+count+"      :     "+o.Name);
                }
    
    
                Console.WriteLine("成功!");
                Console.ReadKey();
            }

    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    
    namespace ConsoleApplication2
    {
        internal class ThumbImage
        {
            /// <summary>
            ///     高质量缩放图片
            /// </summary>
            /// <param name="originFilePath">源图的路径</param>
            /// <param name="targetFilePath">存储缩略图的路径</param>
            /// <param name="destWidth">缩放后图片宽度</param>
            /// <param name="destHeight">缩放后图片高度</param>
            /// <param name="width"></param>
            /// <param name="height"></param>
            /// <returns>表明此次操作是否成功</returns>
            public static bool GetMicroImage(string originFilePath, string targetFilePath, int destWidth, int destHeight,
                out int width, out int height)
            {
                width = 0;
                height = 0;
                try
                {
                    using (Image imgSource = new Bitmap(originFilePath))
                    {
                        width = imgSource.Width;
                        height = imgSource.Height;
                        //System.Drawing.Image imgSource = b;
                        int sW = 0, sH = 0;
                        // 按比例缩放           
                        var sWidth = imgSource.Width;
                        var sHeight = imgSource.Height;
                        if (sHeight > destHeight || sWidth > destWidth)
                        {
                            if ((sWidth*destHeight) > (sHeight*destWidth))
                            {
                                sW = destWidth;
                                sH = (destWidth*sHeight)/sWidth;
                            }
                            else
                            {
                                sH = destHeight;
                                sW = (sWidth*destHeight)/sHeight;
                            }
                        }
                        else
                        {
                            sW = sWidth;
                            sH = sHeight;
                        }
                        var outBmp = new Bitmap(destWidth, destHeight);
                        var g = Graphics.FromImage(outBmp);
                        g.Clear(Color.Transparent);
                        // 设置画布的描绘质量         
                        g.CompositingQuality = CompositingQuality.HighQuality;
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.DrawImage(imgSource, new Rectangle((destWidth - sW)/2, (destHeight - sH)/2, sW, sH), 0, 0,
                            imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
                        g.Dispose();
                        // 以下代码为保存图片时,设置压缩质量     
                        var encoderParams = new EncoderParameters();
                        var quality = new long[1];
                        quality[0] = 100;
                        var encoderParam = new EncoderParameter(Encoder.Quality, quality);
                        encoderParams.Param[0] = encoderParam;
                        outBmp.Save(targetFilePath);
                        outBmp.Dispose();
                    }
                    //压缩一下PNG图
                    //CompressPng(targetFilePath, targetFilePath);
    
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    HTML事件处理程序---内联onclick事件
    js的width函数
    了解跨站请求伪造CSRF
    离线百度地图
    GetOverlappedResult 函数
    OVERLAPPED 结构
    SetupDi系列函数
    Linux 各个命令的缩写原型
    Linux grep命令
    Linux if[......] then ......else...... fi
  • 原文地址:https://www.cnblogs.com/littlehb/p/5500774.html
Copyright © 2020-2023  润新知