在 C 或 C++ 中将 JPEG 或 PNG 图像作为像素数据打开
opening a jpeg or png image as pixel data in c or c++
这是我的第一篇文章,所以如果我没有清楚地转述这个问题,请告诉我。
我正在尝试在 Dev C++ 中将(黑白(JPEG 或 PNG 图像文件作为数组打开,以便我可以隔离白色像素的位置。 我理解的隔离的指针和循环。 但是,打开图像文件不起作用,并且无法找到我可以使用的示例。 除了给定的 #include "cstdlib" #include "iostream" #include "stdio.h">
我没有其他头文件。我知道 FOPEN 用于文件打开,但是我的尝试都没有显示图像的数据。
感谢您的任何帮助
这不是我的代码。这是提供给BIV1991示例我正在发布是因为找不到 GDIoPlus.h 的标题。建议使用标题unknwn,Windows,objidl来解决这个问题
#include <cstdlib>
#include <iostream>
#include <Unknwn.h>
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib,"gdiplus.lib")
int main(int argc, char *argv[])
{
// initialize gdiplus
Gdiplus::GdiplusStartupInput si;
ULONG_PTR token;
Gdiplus::GdiplusStartup(&token,&si,0);
// load image as bitmap, any formats supported
Gdiplus::Bitmap image(L"C:\image.jpg",false);
int w = image.GetWidth();
// image.LockBits - to read pixels
system("PAUSE");
return EXIT_SUCCESS;
}
如果您为 Windows 编程,您可以使用 GDIPlus 读取 Jpeg 和其他图像类型并对其进行操作,例如绘制或获取它们的像素。保证100%。我做过很多次。
要包括的内容:
#include <gdiplus.h>
#pragma comment(lib,"gdiplus.lib")
在代码中执行的操作:
// initialize gdiplus
Gdiplus::GdiplusStartupInput si;
ULONG_PTR token;
Gdiplus::GdiplusStartup(&token,&si,0);
// load image, any formats supported
Gdiplus::Bitmap image(L"C:\image.jpg",false);
int w = image.GetWidth();
// image.LockBits - to read pixels
首先,没有标准的C++库来处理图像。其次,jpeg 和 png 图像格式是压缩图像格式,需要某种复杂的解压缩算法。因此,要开始使用图像,您有两种方法:
-
使用简单的图像格式,如bmp.bmp只是像素缓冲区带有一些光标题,描述该像素缓冲区格式。您可以编写一个程序,将BMP加载到我们自己的一半(并浪费(大约一个小时来理解格式本身(。更多关于 bmp 的信息:http://en.wikipedia.org/wiki/BMP_file_format。
-
使用外部 图书馆。也就是说,您没有此库与您的语言或 编译器包。您需要下载甚至安装它 有时。一般来说,要使用外部库,你需要做五个 大腿:1(在互联网上查找图像处理库。2(将xxx.lib文件放在您的项目文件夹中。3(告诉你的链接器你想使用xxx.lib 4(添加你的代码 #include"xxx.h"。5( 使用库 API 加载图像。
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 计算另一个图像像素满足条件的像素值的平均值
- 如何返回定义良好的内存部分?例如来自图像数据的像素的颜色值
- 如何从窗口中获取像素数据像素缓冲区并提取RGB
- 覆盖openGL 2d纹理中的每像素像素
- 有没有办法在不复制所有像素的情况下将现有的像素数组转换为位图