문제

I want to view (only) images files and some common documents (PDF, RTF, TEXT, etc) in my Delphi program, I've found two ways of doing that,

  1. via AtViewer, but the file size is too large.
  2. Via the embedded Internet Explorer installed on the end user's computer directly.

I'm wondering, are there alternatives? Thanks.

도움이 되었습니까?

해결책

There are two ways to go here:

  1. Use whatever software is provided by Windows
  2. Stick to native Delphi components

I personally like to keep my source "all delphi". When it comes to displaying images Delphi is blessed with many third party libraries that provides you with support for almost every image format imaginable.

Images

ImageEN is a good package (commercial) and you might also like the free Vapyre Image Library (the name is a bit.. well, but its a great product). To quickly add support for the most common formats, GraphicsEX is a traditional Delphi extension a lot of developers use. You also have FreeImage, which is collection of DLL files - but with Delphi wrapper classes to make them easy to use. take a look in the graphics section on Torry's Delphi Pages (google it) and you will find robust support.

PDF

For PDF preview/reading I would take a look at Gnostice's product-line. They provide native Delphi components for generating and viewing PDF files (http://www.gnostice.com/). Alternatively (for PDF) I would probably go for the ActiveX components that ship with Adobe's PDF reader. But then you will have to check that these objects are registered and available to your application at startup.

So for your "universal viewer" I would

  1. Create a base viewer-form (to provide buttons, statusbar etc.)
  2. Add a virtual method for opening a file
  3. Decend 3 forms from this that each deal with a different media type. So you get TfrmPDF, TfrmImage and TfrmHTML. In each, override the open() method. This way your main application dont have to bother with the details of each format.

HTML

For viewing HTML you are in luck, as Delphi has it's own native Web renderer. It was written by Steve Baldwin and is called THTMLViewer. It has been released as opensource and you will find it on google projects.

다른 팁

Windows (since XP if I recall correctly) uses the IExtractImage interface to generate a thumbnail for any file in thumbnails view, if it has an object listed for its file type.

These objects are accessible by code, and you can use them to generate thumbnails for any file which would get a thumbnail in Windows Explorer as well. (I even think thumbnails will be served from the thumbnail cache (Thumbs.db) if it's available in the image size you're requesting.)

There's more here: http://yoy.be/item.asp?i1490 or here: http://msdn.microsoft.com/en-us/library/bb775073(v=vs.85).aspx

I would suggest that you write your own viewer TForm, that looks at the file to be viewed and does one of three (or four, or five) things with it:

  1. If it's a PDF, or HTML, load it with an embedded IE webbrowser (TEmbeddedWB from www.bsalsa.com is better than the included VCL IE wrapper TwebBrowser).

  2. If it's an image, load it into an image viewer control that has resize/scaleing/scrolling support.

  3. If it's a text file, or RTF file, load it into a RichEdit.

  4. If it's an OLE type, you can view it in an OLE container view.

The embedded viewer will display any documents - however if it something that requires an external viewer, then this will be shown outside of IE - TIFFs for each are displayed (by default) in the image viewer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top