How to implement an image or pdf viewer?

我与影子孤独终老i 提交于 2020-01-25 13:15:21

问题


for learning purposes I would like to know how to implement an image (and/or) pdf viewer on my own.

I'm interested in the general approach to implement such a thing.

I already read about the different formats on the net (tiff/pdf) so I found out that these files have a special format which describes where I have to look for a header, where the footer is and where the image information (in decrypted form) is.

Because I think such a viewer works sth. like:

  • opening the file
  • reading different file information (header, footer, etc.)
  • "translate" pixel positions

I need to know, how to get the pixel positions (in case of a tiff file).

How to create this as a control? Where do I have to put the pixels onto?

Feel free to correct me if I'm wrong, because ATM I don't really have an idea and everything is just speculation.

Regards,

inno

P.S.: I would prefer a solution in C#, but if it's in another language, it's ok, too. Platform should be Microsoft Windows (first of all).

P.P.S.: It should work without an already installed pdf-/viewing-application.


回答1:


For any viewer like that you will have to look up the specs for each file type you want to display and figure out how its data is encoded. Some image formats build on others, or use similar encoding techniques, while others are completely different from each other. PDF is another beast. I've done a bit of work with it and from what I remember (I could be wrong, it's been a while) it basically represents itself as a series of objects, each with unique position, size and assorted attributes dependent on the object type.

I would take a look at Wikipedia. It actually has some really good articles on some of the different image formats.

http://en.wikipedia.org/wiki/JPEG

And it will definitely point you to the official standards documents for each format you want to cover.

Ultimately you will probably end up having to read/implement the rfc for each format:

JPEG - http://tools.ietf.org/html/rfc1341
PNG - http://www.faqs.org/rfcs/rfc2083.html
GIF - http://www.w3.org/Graphics/GIF/spec-gif89a.txt
BMP - http://www.faqs.org/rfcs/rfc797.html

HTH




回答2:


Here is the way for converting your image into byte array.

 public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}

How to create this as a control? Where do I have to put the pixels onto? this byte array contains your image pixel data.(See what is your image type 8bit or 16 bit) Now you can draw your images into any panel and make it as a custom control.

I don't know about the pdf format.



来源:https://stackoverflow.com/questions/3396146/how-to-implement-an-image-or-pdf-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!