Beispiel #1
0
        /// <summary>
        /// イメージを読み込む、同じイメージは読み込まない
        /// </summary>
        /// <param name="fileName">ファイル名</param>
        /// <returns>読み込みエラーのときはfalseを返す。 成功時には、trueを返す</returns>
        bool ImageFileLoad(string fileName)
        {
            ListViewItem listVI;
            string       fullPas;

            if (fileName == "")
            {
                return(false);
            }

            if (m_readFileName == fileName)
            {
                return(true);
            }

            m_readFileName = fileName;
            fullPas        = CommonMC2D.Instance.DirPathMC2D;
            fullPas       += @"\Media\images\";
            fullPas       += m_betweenDir;
            fullPas       += fileName;

            // フルパス取得
            m_readFullPathFileName = fullPas;
            // イメージのセレクト
            ImageFileInfo imgInfo;

            //
            try{
                pictureBoxImg.Image = ReadImage.DrawingBitmap(fullPas);
            }catch {
                return(false);
            }
            listViewImgInfo.Items.Clear();

            try
            {
                imgInfo = new ImageFileInfo(fullPas);
            }
            catch
            {
                return(false);
            }
            //==========================================
            //---- ListView
            //Win32.SHGetFileInfo(strFullPas, Win32.FILE_ATTRIBUTE_ARCHIVE, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_EXETYPE | Win32.SHGFI_TYPENAME);
            Shell32.CItem item1 = new Shell32.CItem();
            Shell32.GetFileInfo(fullPas, ref item1);
            listVI = new ListViewItem(new string[] { "画像の種類", imgInfo.Type.ToString() });
            listViewImgInfo.Items.Add(listVI);

            // Property 幅高さ
            fullPas = string.Format("{0:D} × {1:D}", imgInfo.Width, imgInfo.Height);
            listVI  = new ListViewItem(new string[] { "幅×高", fullPas });
            listViewImgInfo.Items.Add(listVI);

            if (imgInfo.Type == MC_FILE_TYPE.DDS)
            {
                //// Property フォーマット
                //fullPas = imgInfo.MetadataDDS.;
                //listVI = new ListViewItem(new string[] { "フォーマット", fullPas });
                //listViewImgInfo.Items.Add(listVI);

                //// Property ビットの深さ
                //fullPas = string.Format("{0:D}", imgInfo.MetadataDDS.);
                //listVI = new ListViewItem(new string[] { "深度", fullPas });
                //listViewImgInfo.Items.Add(listVI);

                //// Property ミップレベル
                //fullPas = string.Format("{0:D}", imgInfo.MetadataDDS);
                //listVI = new ListViewItem(new string[] { "ミップレベル", fullPas });
                //listViewImgInfo.Items.Add(listVI);

                //// Property リソースタイプ
                ////strFullPas = txInfo.ResourceType.ToString();
                ////listVI = new ListViewItem(new string[] { "リソースタイプ", strFullPas });
                ////listViewImgInfo.Items.Add(listVI);
            }


            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 获取系统图标并缓存
        /// </summary>
        /// <param name="fsFullPath">完整路径</param>
        /// <param name="shFileInfo">同时传出文件系统信息</param>
        /// <param name="Expanded">是否获取展开图标</param>
        /// <returns></returns>
        public static Icon GetFileSystemIcon(string fsFullPath, ref Shell32.SHFILEINFO shFileInfo, bool Expanded = false)
        {
            if (!Path.IsPathRooted(fsFullPath))
            {
                return(null);
            }

            Icon SmallIcon = null;

            if (File.Exists(fsFullPath))
            {            //文件
                FileInfo diChild = new FileInfo(fsFullPath);
                string   strExt  = diChild.Extension.ToLower();
                if (strExt == ".exe")
                {
                    strExt = diChild.FullName.ToLower();
                }

                SmallIcon = Shell32.GetFileInfo(strExt, ref shFileInfo);

                if (!ImgList.Images.ContainsKey(strExt))
                {
                    ImgList.Images.Add(strExt, SmallIcon);
                }
            }
            else if (Directory.Exists(fsFullPath))
            {            //文件夹或盘符
                if (fsFullPath.Length == 3)
                {        //盘符
                    string    cDrive = fsFullPath.Substring(0, 1);
                    DriveInfo di     = new DriveInfo(cDrive);
                    SmallIcon = Shell32.GetFileInfo(fsFullPath, ref shFileInfo);

                    if (!ImgList.Images.ContainsKey(shFileInfo.szTypeName))
                    {
                        ImgList.Images.Add(shFileInfo.szTypeName, SmallIcon);
                    }
                }
                else if (Expanded)
                {                //文件夹展开
                    if (!ImgList.Images.ContainsKey("文件夹展开"))
                    {
                        SmallIcon = Shell32.GetFolderIcon(ref shFileInfo, false, true);
                        ImgList.Images.Add("文件夹展开", SmallIcon);
                    }
                    Bitmap bmp = new Bitmap(ImgList.Images["文件夹展开"]);
                    SmallIcon = Icon.FromHandle(bmp.GetHicon());
                }
                else
                {                //文件夹收起
                    if (!ImgList.Images.ContainsKey("文件夹收起"))
                    {
                        SmallIcon = Apq.DllImports.Shell32.GetFolderIcon(ref shFileInfo);
                        ImgList.Images.Add("文件夹收起", SmallIcon);
                    }
                    Bitmap bmp = new Bitmap(ImgList.Images["文件夹收起"]);
                    SmallIcon = Icon.FromHandle(bmp.GetHicon());
                }
            }
            else
            {            //盘符
                string    cDrive = fsFullPath.Substring(0, 1);
                DriveInfo di     = new DriveInfo(cDrive);
                SmallIcon = Shell32.GetFileInfo(fsFullPath, ref shFileInfo);

                if (!ImgList.Images.ContainsKey(shFileInfo.szTypeName))
                {
                    ImgList.Images.Add(shFileInfo.szTypeName, SmallIcon);
                }
            }

            return(SmallIcon);
        }