How to implement an image or pdf viewer?

2019-08-21 07:03发布

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.

2条回答
孤傲高冷的网名
2楼-- · 2019-08-21 07:18

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.

查看更多
欢心
3楼-- · 2019-08-21 07:25

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

查看更多
登录 后发表回答