在C或C ++中将jpeg或png图像打开为像素数据 [英] opening a jpeg or png image as pixel data in c or c++

查看:90
本文介绍了在C或C ++中将jpeg或png图像打开为像素数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第一篇文章,所以如果我没有清楚地回答这个问题,请告诉我.

this is my first post so please let me know if i dont relay the question clearly.

我正在尝试在dev c ++中将一个(黑白)jpeg或png图像文件打开为数组,以便可以隔离白色像素的位置.指针,并为我理解的隔离循环.但是,打开图像文件无法正常工作,并且无法找到我可以使用的示例.除了给定的#include"cstdlib"#include"iostream"#include"stdio.h"

i am trying to open a (black and white) jpeg or png image file as an array in dev c++ so that i can isolate the place of the white pixels. the pointers, and loops for the isolation i understand. however, opening the image file has not worked and have been unable to find an example that i can use. besides the given #include "cstdlib" #include "iostream" #include "stdio.h"

我没有其他头文件.我知道fopen可以打开文件,但是我的尝试都没有显示图像的数据.

i have no other header files. i know fopen for file open, however none of my attempts have displayed the data of the image.

感谢您的帮助

这不是我的密码.这是BIV1991提供给我的示例我正在发布,因为找不到gdiplus.h的标头.建议使用标题unknwn,windows,objidl来解决该问题

THIS IS NOT MY CODE. THIS IS BIV1991 EXAMPLE PROVIDED TO ME i am posting because the header for gdiplus.h is not being located. the header unknwn, windows,objidl were suggested to solve that problem

#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;
}

推荐答案

首先,没有标准的C ++库来处理图像.其次,jpeg和png图像格式是压缩图像格式,需要某种复杂的解压缩算法.因此,要开始使用图像,您有两种方法:

To start with, there is no standard C++ library to process images. Secondly, jpeg and png image formats are compressed image formats that need some complex sort of decompressing algorithm. So to start work with images you have two ways:

  1. 使用简单的图像格式,如bmp.bmp只是像素缓冲区带有一些浅标题,描述了该像素缓冲区的格式.你可以自己编写一个程序将bmp加载成一半(浪费)大约需要一个小时才能了解格式本身).关于bmp的更多信息: http://en.wikipedia.org/wiki/BMP_file_format .

使用外部图书馆.也就是说,您没有使用该语言的该库,或者编译器包.您需要下载甚至安装它有时.通常,要使用外部库,您需要做五件事大腿:1)在Internet中找到图像处理库.2)将xxx.lib文件放在您的项目文件夹中.3)告诉您的链接器您要使用xxx.lib.4)在您的代码中添加#include"xxx.h".5)使用库API加载图像.

Using EXTERNAL library. That is, you don't have this library with your language or compiler package. You need to download and even install it sometimes. In general, to use external library you need to do five thighs: 1) Find image processing library in Internet. 2) Put xxx.lib file in your project folder. 3) Tell your linker you want to use xxx.lib 4) Add in your code #include "xxx.h". 5) Use library API to load image.

这篇关于在C或C ++中将jpeg或png图像打开为像素数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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