C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 12 を表示中)
■3122 / )  IExtractImageによるサムネイルの取得
□投稿者/ zen (1回)-(2007/04/24(Tue) 09:42:58)

分類:[C# (Windows)] 

エクスプローラーで「表示→縮小版」を選択した際に表示されるサムネイルを取得する
方法として、IExtractImageを用いました。
パワーポイントもエクセルもワードも動画ファイルもエクスプローラで「縮小版」時に
サムネイルが出る物ならなんでもとれるようになった・・・と思ったのですが、
何故かPDFだけ、取得できません。エクスプローラ上ではサムネイルが表示されているのですが・・・
素材の元にさせていただいたVB6のアプリでちゃんとPDFのサムネイルもとれるのですが・・・
(そのVB6のソースをC#に変換したつもりなのですが・・・)
いろいろ調べたつもりなのですが、どうしてもわかりません。

ご教授いただけないでしょうか。よろしくお願いします。

private bool showThumbnail(string fileName)
{
    IShellFolder ishell = null;
    string folder = "";
    System.IntPtr ppidl; 
    uint pdwAttributes = 0;
    uint pchEaten = 0;
    IExtractImage ieimg = null;
    IntPtr phBmpThumbnail = IntPtr.Zero;

    folder = fileName.Substring(0,fileName.LastIndexOf("\\"))+"\\";
    fileName = fileName.Substring(fileName.LastIndexOf("\\")+1);

    ishell = ShellFunctions.GetDesktopFolder();
    ishell.ParseDisplayName(IntPtr.Zero,System.IntPtr.Zero,folder,ref pchEaten ,out ppidl,ref pdwAttributes);

    if (ppidl!=System.IntPtr.Zero)
    {
        mobjDesktop.BindToObject(ppidl,System.IntPtr.Zero,ref rid,ref ishell);
        ShellFunctions.GetMalloc().Free(ppidl);
        ppidl=System.IntPtr.Zero;
    }
    if (ishell==null)
    {
        return false;
    }

    ishell.ParseDisplayName(IntPtr.Zero,IntPtr.Zero,fileName,ref pchEaten,out ppidl,ref pdwAttributes);

    pchEaten = 0;
    if (ppidl!=IntPtr.Zero)
    {
        ishell.GetUIObjectOf(IntPtr.Zero, 1, ref ppidl, ref irid, ref pchEaten, out ieimg);
        
        if (ieimg!=null)
        {
            StringBuilder sb = new StringBuilder(1024);
            SIZE size = new SIZE();
            size.cx = 96;
            size.cy = 96;
            int pdwPriority = 0;
            int pdwFlags = (int)(EIEIFLAG.IEIFLAG_ORIGSIZE|EIEIFLAG.IEIFLAG_SCREEN);;
            ieimg.GetLocation(sb,sb.Capacity,ref pdwPriority,ref size,32,ref pdwFlags);
            this.label1.Text = sb.ToString();
            ieimg.Extract(out phBmpThumbnail);
        }
        ShellFunctions.GetMalloc().Free(ppidl);
    }
    
    if (phBmpThumbnail!=IntPtr.Zero)
    {
        Image img = null;
        if (this.pictureBox1.Image!=null)
        {
            img = this.pictureBox1.Image;
            this.pictureBox1.Image = null;
            img.Dispose();
        }
        img = Image.FromHbitmap(phBmpThumbnail);
        this.pictureBox1.Image = img;
    }

    if (ishell!=null)
    {
        Marshal.ReleaseComObject(ishell);
    }
    if (ieimg!=null)
    {
        Marshal.ReleaseComObject(ieimg);
    }

    return true;
}

返信 編集キー/


管理者用

- Child Tree -