使用ifstream获取图像的像素 [英] Getting pixel of the image using ifstream

查看:80
本文介绍了使用ifstream获取图像的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何读取bmp图像格式的像素?我已经使用了fread功能,但我有无意义的信息。我应该正确阅读吗?

我应该跳过它的标题大小是什么?

我想要知道,当你用记事本++打开一个bmp图像时,输出是什么?为什么无法读取图像信息,通过这个程序(记事本++)?

How can i read pixels of bmp image format ? i have used fread function but i have got meaningless information.how should i read it correctly?
what is the header size that i should skip it ?
and i want to know , when you open a bmp image by notepad++ ,what is the output ? why can not read an image information, by this program (notepad++) ?

推荐答案

位图文件不兼容记事本,也不是只是一块简单的数据。



位图文件存储为二进制数据,而不是字符,并不是人类可读的。当您使用任何文本类型的编辑器应用程序打开它时,如果您很幸运,您将获得(非常无意义的)十六进制显示。如果你运气不好,你会得到一个充满异形斑点和问号的显示器。



您可以直接将位图文件读入您​​的程序,作为一个字节序列 - 但除非你正确处理这些字节,否则它仍然没有多大意义;那里有更多,而不仅仅是像素。 维基百科 [ ^ ]解释得非常好。



有一种更简单的方法:将BMP文件作为图像读取并让现有代码处理文件格式:然后它会向您显示数据和(通常,取决于系统)函数,以便在需要时以像素为基础访问和操作图像数据。



我不知道你正在使用什么语言,或者你正在构建的系统,所以我无法帮助你 - 但是开始寻找图像类或函数并从那里开始。
Bitmap files are not Notepad compatible, and aren't just a block of simple data either.

Bitmap files are stored as binary data, not characters and are not intended to be human readable. When you open it with any text-type editor application, if you are lucky you will get a (pretty meaningless) hexadecimal display. If you are unlucky, you will get a display full of odd shaped blobs and question marks for the most part.

You can read a bitmap file directly into your program, as a sequence of bytes - but unless you process those bytes correctly, it still isn't going to make much sense; there is more in there than just the pixels. Wikipedia[^] explains it pretty well.

There is an easier way: read the BMP file as an image and let existing code handle the file format: it will then present you with data and (normally, depending on the system) functions to access and manipulate the image data on a pixel basis if needs be.

I have no idea what language you are using, or system you are building for, so I can't help you any further - but start looking for an image class or function and start from there.


这篇关于使用ifstream获取图像的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆