当前位置:首页 » 编程语言 » c语言像素怎么输出
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言像素怎么输出

发布时间: 2022-08-01 18:04:35

⑴ 如何用c语言输出结果

一般格式

printf(格式控制,输出表列) 。

说明:

(1)“格式控制”是用双撇号括起来的字符串,也称“转换控制字符串”,它包括两种信息:

①格式说明:由“%”和格式字符组成,它的作用是将输出的数据转换为指定的格式输出。

②普通字符,即需要原样输出的字符。

(2)“输出表列”是需要输出的一些数据,可以是表达式 。

(3) printf函数的一般形式可以表示为printf(参数1,参数2,„„,参数n) 。

功能是将参数2~参数n按参数1给定的格式输出

⑵ C语言输出图片

输出BMP图片的:
#include "stdlib.h"
#include "graphics.h"
#include "stdio.h"

#define WIDTH 120
#define HEIGHT 120
//用一个二维数组保存的图片,这里图片长高必须是4的倍数,不是4的倍数必须进行补齐,
//但是这里面是没有进行补位操作的,你也可以自己去看看24位bmp图片的编码格式,
//然后就知道该怎么用了
void mian()
{
FILE *fp;
unsigned char bmp[16][200];
unsigned char bmp2[WIDTH][HEIGHT*3];
int i = 1,size1 = 0,size2 = 0,size0 = 0;
int j = 0;
if((fp = fopen("G:\\new\\Boy5.bmp","rb")) == NULL)//打开图片
exit(0);
i = 0;
fseek(fp,54L,0);//BMP图片阵列是从第54位开始
//#########读入图片阵列到数组中##########
while(i < WIDTH*HEIGHT*3)
{
*(bmp2[0]+i) = fgetc(fp);
i++;
}
fclose(fp);
initgraph(700, 700); // 打开图形窗口,这里这个函数我之前是在VC下编译的,用了一个网上的绘图库,与TC的打开图形界面函数有所差别,改掉就可以了
//####################################输出图片,这里是打点的方式在图形界面输出,
for(i = 0;i < (WIDTH-1);)
{
for(j =0;j < (HEIGHT-1)*3 ;)
{
putpixel(50+(j/3),600-(i/1),RGB((int)bmp2[i][j+2],(int)bmp2[i][j+3],(int)bmp2[i][j+4]));//输出像素点
j+=3;
}
i++;
}
getchar();
closegraph(); // 关闭图形窗口
}

⑶ C语言打开图像文件后读取像素

C语言打开图像文件后运用以下代码就可以读取像素,具体如下:
#ifndef IMAGE_H
#define IMAGE_H
void image_info(FILE* file);
void image_save(FILE *file);
void image_gray();
void image_binarization();
void image_opposite();
void image_channel(); //抽取RGB通道
void image_bright();//改变图像亮度

typedef struct BMP
{
//14字节
unsigned short bfType; //文件标识 2字节 必须为BM
unsigned int bfSize; //文件大小 4字节
unsigned short bfReserved1; //保留,每字节以"00"填写 2字节
unsigned short bfReserved2; //同上 2字节
unsigned int bfOffBits; //记录图像数据区的起始位置(图象数据相对于文件头字节的偏移量)。 4字节

//40字节
unsigned int biSize; //表示本结构的大小 4字节
int biWidth; //位图的宽度 4字节
int biHeight; //位图的高度 4字节
unsigned short biPlanes; //永远为1 , 2字节
unsigned short biBitCount; //位图的位数 分为1 4 8 16 24 32 2字节
unsigned int biCompression; //压缩说明 4字节
unsigned int biSizeImage; //表示位图数据区域的大小以字节为单位 4字节
int biXPelsPerMeter; //用象素/米表示的水平分辨率 4字节
int biYPelsPerMeter; //用象素/米表示的垂直分辨率 4字节
unsigned int biClrUsed; //位图使用的颜色索引数 4字节
unsigned int biClrImportant; //对图象显示有重要影响的颜色索引的数目 4字节

} BMP;

int line_byte;
unsigned char *imagedata;
extern BMP bmp;
extern int line_byte;
extern unsigned char *imagedata;
#endif

//image_rw.c文件

#include<stdio.h>
#include<stdlib.h>
#include"image.h"

void image_info(FILE *file)
{

int times=3; //输入文件名次数。
char bmp_name[10]; //文件名

printf("\nplease enter a file name for reading:");
do
{
if (times<3)
{
printf("\nplease enter a file name for reading again:");
}
fflush(stdin);
gets(bmp_name);
//printf("\n%s",bmp_name);
file=fopen(bmp_name,"rb+"); //打开一个文件进行读写操作。
--times;
if (file==NULL)
{
printf("\nerror opening %s for reading! ",bmp_name);
}
else
{
break;
}
}
while(times!=0);

if (times==0)
{
printf("\nsorry, shutdown!");
exit(1);
}

//读取图像信息

fseek(file,0L,0); //读取图像文件类型
fread(&bmp,sizeof(BMP),1,file);
printf("\n bmp tpye: %u",bmp.bfType);
printf("\n bmp size: %u",bmp.bfSize);
printf("\n bmp reserved1: %u",bmp.bfReserved1);
printf("\n bmp reserved2: %u",bmp.bfReserved2);
printf("\n bmp offBits: %u",bmp.bfOffBits);

printf("\n bmp bisize: %u",bmp.biSize);
printf("\n bmp biWidth: %d",bmp.biWidth);
printf("\n bmp biHeight: %d",bmp.biHeight);
printf("\n bmp biplans: %u",bmp.biPlanes);
printf("\n bmp biBitCount: %u",bmp.biBitCount);
printf("\n bmp biCompression: %u",bmp.biCompression);
printf("\n bmp biSizeImage: %u",bmp.biSizeImage);
printf("\n bmp biXPelsPerMeter: %d",bmp.biXPelsPerMeter);
printf("\n bmp biYPelsPerMeter: %d",bmp.biYPelsPerMeter);
printf("\n bmp biClrUsed: %u",bmp.biClrUsed);
printf("\n bmp biClrImportant: %u\n",bmp.biClrImportant);

line_byte=(bmp.biWidth*bmp.biBitCount/8+3)/4*4; //获得图像数据每行的数据个数
//printf("dfsa%u",bmp.line_byte);
//bmp.imagedata=NULL;
imagedata=(unsigned char*)malloc(bmp.biSizeImage);

fseek(file,(long)bmp.bfOffBits,0);
fread(imagedata,sizeof(unsigned char),bmp.biSizeImage,file);

fclose(file);
}

//保存图像
void image_save(FILE *file)
{
int times=3; //输入文件名次数。
char bmp_name[10]; //文件名
//int i; //记录数据区个数

printf("\nplease enter a file name for writeing:");
do
{
if (times<3)
{
printf("\nplease enter a file name for writeing again:");
}
fflush(stdin);
gets(bmp_name);
printf("\n%s",bmp_name);
file=fopen(bmp_name,"wb+"); //打开一个文件进行读写操作。
--times;
if (file==NULL)
{
printf("\nerror opening %s for writing",bmp_name);
}
else
{
break;
}
}
while(times!=0);

if (times==0)
{
printf("\nsorry, shutdown!");
exit(1);
}

//写文件头
printf("\n%s",bmp_name);
fseek(file,0L,0); //图像文件类型
fwrite(&(bmp.bfType),sizeof(short),1,file);
printf("\n bmp tpye: %d",bmp.bfType);

fseek(file,2L,0); //图像文件大小
fwrite(&(bmp.bfSize),sizeof(int),1,file);
printf("\n bmp size: %d",bmp.bfSize);

fseek(file,6L,0); //图像文件保留字1
fwrite(&(bmp.bfReserved1),sizeof(short),1,file);
printf("\n bmp reserved1: %d",bmp.bfReserved1);

fseek(file,8L,0); //图像文件保留字2
fwrite(&(bmp.bfReserved2),sizeof(short),1,file);
printf("\n bmp reserved2: %d",bmp.bfReserved2);

fseek(file,10L,0);//数据区的偏移量
fwrite(&(bmp.bfOffBits),sizeof(short),1,file);
printf("\n bmp offBits: %d",bmp.bfOffBits);

fseek(file,14L,0);//文件头结构大小
fwrite(&(bmp.biSize),sizeof(int),1,file);
printf("\n bmp bisize: %d",bmp.biSize);

fseek(file,18L,0);//图像的宽度
fwrite(&(bmp.biWidth),sizeof(int),1,file);
printf("\n bmp biWidth: %d",bmp.biWidth);

fseek(file,22L,0);//图像的高度
fwrite(&(bmp.biHeight),sizeof(int),1,file);
printf("\n bmp biHeight: %d",bmp.biHeight);

fseek(file,24L,0);//图像的面数
fwrite(&(bmp.biPlanes),sizeof(short),1,file);
printf("\n bmp biplans: %d",bmp.biPlanes);

fseek(file,28L,0);//图像一个像素的字节数
fwrite(&(bmp.biBitCount),sizeof(short),1,file);
printf("\n bmp biBitCount: %d",bmp.biBitCount);

fseek(file,30L,0);//图像压缩信息
fwrite(&(bmp.biCompression),sizeof(short),1,file);
printf("\n bmp biCompression: %d",bmp.biCompression);

fseek(file,34L,0);//图像数据区的大小
fwrite(&(bmp.biSizeImage),sizeof(int),1,file);
printf("\n bmp biSizeImage: %d",bmp.biSizeImage);

fseek(file,38L,0);//水平分辨率
fwrite(&(bmp.biXPelsPerMeter),sizeof(int),1,file);
printf("\n bmp biXPelsPerMeter: %d",bmp.biXPelsPerMeter);

fseek(file,42L,0);//垂直分辨率
fwrite(&(bmp.biYPelsPerMeter),sizeof(int),1,file);
printf("\n bmp biYPelsPerMeter: %d",bmp.biYPelsPerMeter);

fseek(file,46L,0);//颜色索引数
fwrite(&(bmp.biClrUsed),sizeof(int),1,file);
printf("\n bmp biClrUsed: %d",bmp.biClrUsed);

fseek(file,50L,0);//重要颜色索引数
fwrite(&(bmp.biClrImportant),sizeof(int),1,file);
printf("\n bmp biClrImportant: %d\n",bmp.biClrImportant);

fseek(file,(long)(bmp.bfOffBits),0);
fwrite(imagedata,sizeof(unsigned char),bmp.biSizeImage,file);

fclose(file);
}

//pixProcess.c文件

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include"image.h"

//灰度化
void image_gray()
{
int i,j;
unsigned char tmp;
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte/3;j++)
{
tmp=0.11*(*(imagedata+i*line_byte+j*3+0))+0.59*(*(imagedata+i*line_byte+j*3+1))+0.3*(*(imagedata+i*line_byte+j*3+2));
imagedata[i*line_byte+j*3+0]=tmp;
imagedata[i*line_byte+j*3+1]=tmp;
imagedata[i*line_byte+j*3+2]=tmp;
//printf("\nnidsfh%d %d",i,j);
}
}
}

//二值化

void image_binarization()
{
int i,j;
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte;j++)
{
if ((*(imagedata+i*line_byte+j))<128)
{
imagedata[i*line_byte+j]=0;
}
else
{
imagedata[i*line_byte+j]=255;
}
}
}
}

void image_opposite() //反相
{
int i,j;
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte;j++)
{
imagedata[i*line_byte+j]=abs(255-imagedata[i*line_byte+j]);
}
}
}

void image_channel() //抽取RGB通道
{
int i,j;
char rgb;
printf("\nplease enter a char(r/g/b): ");
fflush(stdin);
scanf("%c",&rgb);
if (rgb=='b')
{
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte/3;j++)
{
imagedata[i*line_byte+3*j+1]=0;
imagedata[i*line_byte+3*j+2]=0;
}
}
}
else if(rgb=='g')
{
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte/3;j++)
{
imagedata[i*line_byte+3*j]=0;
imagedata[i*line_byte+3*j+2]=0;
}
}
}
else
{
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte/3;j++)
{
imagedata[i*line_byte+3*j]=0;
imagedata[i*line_byte+3*j+1]=0;
}
}
}

}

void image_bright()//改变图像亮度
{
int level;
int i,j;
printf("\n please enter the level of brightness[-255 to 255] :");
fflush(stdin);
scanf("%d",&level);
for (i=0;i<bmp.biHeight;i++)
{
for (j=0;j<line_byte;j++)
{
if (level>=0)
{

if ((imagedata[i*line_byte+j]+level)>255)
imagedata[i*line_byte+j]=255;
else
imagedata[i*line_byte+j]+=level;
}
else
{
if ((imagedata[i*line_byte+j]-abs(level))<0)
imagedata[i*line_byte+j]=0;
else
imagedata[i*line_byte+j]+=level;
}

}
}
}

//void image_create() //创建一幅24位BMP图像文件。
//{

//main.c文件

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include"image.h"

BMP bmp;

int main()
{
FILE *file=NULL;
int choose;
char gono;
do
{
image_info(file); //imagedata已经分配了动态内存,但是没有释放

printf("\n 1.image_opposite");
printf("\n 2.image_gray");
printf("\n 3.image_binarization");
printf("\n 4.image_channel");
printf("\n 5.image_brightness");
//printf("6.image_opposite");
//printf("7.image_opposite");

printf("\nchoose your options:");
fflush(stdin);
scanf("%d",&choose);
switch(choose)
{

case 1:
image_opposite();
image_save(file);
free(imagedata);
break;
case 2:
image_gray();
image_save(file);
free(imagedata);
break;
case 3:
image_binarization();
image_save(file);
free(imagedata);
break;
case 4:
image_channel();
image_save(file);
free(imagedata);
break;
case 5:
image_bright();
image_save(file);
free(imagedata);
break;
default:
printf("\n wrong choose!");

}

printf("\nlet's go on?(y/n):");
fflush(stdin);
scanf("%c",&gono);
if (gono=='n')
{
printf("\nbye bye!");
break;
}
}
while(1);

return 0;
}

⑷ c语言中如何输出图像

lz需要弄清楚,你要输出什么格式的图像,bmp,JPG。。。不同格式的图像的数据内部结构是不一样的,弄清楚不同格式图片的数据结构组成,直接采用相应地算法,用C语言文件输出函数(fopen,fprintf……那几个函数,具体我也忘了怎么用了)将数据点写入文件就行了。

⑸ 如何利用c语言实现像素图形的输出

1、可以变成灰度图也可以不变。这里假设你的图像都是IPL_DEPTH_8U类型。

2、如果变成灰度图,就是单通道图像,获取的就是每一个像素点的灰度值。
IplImage* img = cvLoadImage("test.bmp", 0);
for (int i = 0; i < img->height; i++)
{
for (int j = 0; j < img->width; j++)
{
//方法一:使用cvGet2D()函数间接访问
CvScalar s = cvGet2D(img, i, j); //其中i代表y轴(第i行),即height;j代表x轴(第j列),即width。
printf("gray value=%f\n",s.val[0]);

//方法二:使用直接访问
uchar val = ((uchar *)(img->imageData + i*img->widthStep))[j]; //i和j的意义同上
printf("gray value=%d\n",val);
}
}

3、如果不变成灰度图,就是3通道图像,获取的就是每一个像素点的BGR值,然后分别获取B值,G值和R值。
IplImage* img = cvLoadImage("test.bmp", 1);
for (int i = 0; i < img->height; i++)
{
for (int j = 0; j < img->width; j++)
{
//方法一:使用cvGet2D()函数间接访问
CvScalar s=cvGet2D(img,i,j); //其中i代表y轴(第i行),即height;j代表x轴(第j列),即width。
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]); //注意是BGR顺序

//方法二:使用直接访问
int bVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 0]; // B
int gVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 1]; // G
int rVal = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels + 2]; // R
printf("B=%d, G=%d, R=%d\n",bVal,gVal,rVal); //注意是BGR顺序
}
}

⑹ C语言怎么输出一张图片

输出到文件的话,按照指定图片格式,写入文件即可。

电脑型号:微星 GF63 Thin 9SC

系统版本:Microsoft Windows 10

文本文件

1、打开电脑上要读取的文本文件。



⑺ 怎样用C语言得到jpeg格式或BMP格式的图像的像素的rgb值

原型:
int WINAPI icePub_getImgfilePColor(char *strImgFilename,int x,int y,char *strR,char *strG,char *strB,int flag)
输入:strImgFilename 待处理的图片文件名
x x坐标
y y坐标
flag 输出RGB值的格式,0 10进制,1 16进制
输出:strR R值
strG G值
strB B值
返回码:0 OK;-2 x,y值超出图片长宽

int retCode=-1;
char strR[128],strG[128],strB[128];
Cstring m_mem;

typedef int (WINAPI ICEPUB_GETIMGFILEPCOLOR)(char *strImgFilename,int x,int y,char *strR,char *strG,char *strB,int flag);
ICEPUB_GETIMGFILEPCOLOR *icePub_getImgfilePColor = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
icePub_getImgfilePColor = (ICEPUB_GETIMGFILEPCOLOR *)GetProcAddress(hDLLDrv, "icePub_getImgfilePColor");
if(icePub_getImgfilePColor)
retCode=icePub_getImgfilePColor("a.jpg",100,55,strR,strG,strB,0);
if(hDLLDrv)
FreeLibrary(hDLLDrv);
if(retCode == 0)
m_mem.Format("(x,y):%d,%d\r\nR:%s\r\nG:%s\r\nB:%s",point.x,point.y,strR,strG,strB);
AfxMessageBox(m_mem);

原型:
int WINAPI icePub_imgToFileTextdata(char *strImgFilename,char *strFilename,char *strFenge,int flag)
输入:strImgFilename 待处理图像文件 (会被强制256级灰度化)
strFilename 待生成BMP文本数据文件名
strFenge 列之间分隔符
flag 文本数据格式标志:0 10进制; 1 16进制; 10 RGB16进制
输出:

extern "C"
{
__declspec(dllexport)
int WINAPI icePub_imgToFileTextdata(char *strImgFilename,char *strFilename,char *strFenge,int flag);
}

#pragma comment(lib,"icePubDll.lib")

icePub_imgToFileTextdata("a.jpg","bmpdata.txt",",",0);

原型:
char * WINAPI icePub_getBufferFromImg2(char *strImgFilename,int *width,int *height,int huiGrade)
输入:strImgFilename 图片文件名
huiGrade 图像灰度化标志,0 no; >1 and <=256 灰度级
输出:width 图像宽度
height 图像高度
返回值:图像的点阵数据(按照24位BMP格式)

extern "C"
{
__declspec(dllexport)
char * WINAPI icePub_getBufferFromImg2(char *strImgFilename,int *width,int *height,int huiGrade);
}

#pragma comment(lib,"icePubDll.lib")

char *bmpBuffer=NULL;
int imgWidth, imgHeight;

bmpBuffer = icePub_getBufferFromImg2 ("e:\\a.jpg",&imgWidth,&imgHeight,0);
//然后对bmpBuffer数据处理即可

if(bmpBuffer != NULL)
free(bmpBuffer);

⑻ 如何用c语言printf输出bmp图片的像素信息。

#include<math.h>
#include<iomanip.h>
#include<stdlib.h>
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>

//---------------------------------------------------------------------------------------
//以下该模块是完成BMP图像(彩色图像是24bitRGB各8bit)的像素获取,并存在文件名为xiang_su_.txt中
unsignedchar*pBmpBuf;//读入图像数据的指针

intbmpWidth;//图像的宽
intbmpHeight;//图像的高
RGBQUAD*pColorTable;//颜色表指针

intbiBitCount;//图像类型,每像素位数

//-------------------------------------------------------------------------------------------
//读图像的位图数据、宽、高、颜色表及每像素位数等数据进内存,存放在相应的全局变量中
boolreadBmp(char*bmpName)
{
FILE*fp=fopen(bmpName,"rb");//二进制读方式打开指定的图像文件

if(fp==0)
return0;

//跳过位图文件头结构BITMAPFILEHEADER

fseek(fp,sizeof(BITMAPFILEHEADER),0);

//定义位图信息头结构变量,读取位图信息头进内存,存放在变量head中

BITMAPINFOHEADERhead;

fread(&head,sizeof(BITMAPINFOHEADER),1,fp);//获取图像宽、高、每像素所占位数等信息

bmpWidth=head.biWidth;

bmpHeight=head.biHeight;

biBitCount=head.biBitCount;//定义变量,计算图像每行像素所占的字节数(必须是4的倍数)

intlineByte=(bmpWidth*biBitCount/8+3)/4*4;//灰度图像有颜色表,且颜色表表项为256

if(biBitCount==8)
{

//申请颜色表所需要的空间,读颜色表进内存

pColorTable=newRGBQUAD[256];

fread(pColorTable,sizeof(RGBQUAD),256,fp);

}

//申请位图数据所需要的空间,读位图数据进内存

pBmpBuf=newunsignedchar[lineByte*bmpHeight];

fread(pBmpBuf,1,lineByte*bmpHeight,fp);

fclose(fp);//关闭文件

return1;//读取文件成功
}

//-----------------------------------------------------------------------------------------
//给定一个图像位图数据、宽、高、颜色表指针及每像素所占的位数等信息,将其写到指定文件中
boolsaveBmp(char*bmpName,unsignedchar*imgBuf,intwidth,intheight,intbiBitCount,RGBQUAD*pColorTable)
{

//如果位图数据指针为0,则没有数据传入,函数返回

if(!imgBuf)
return0;

//颜色表大小,以字节为单位,灰度图像颜色表为1024字节,彩色图像颜色表大小为0

intcolorTablesize=0;

if(biBitCount==8)
colorTablesize=1024;

//待存储图像数据每行字节数为4的倍数

intlineByte=(width*biBitCount/8+3)/4*4;

//以二进制写的方式打开文件

FILE*fp=fopen(bmpName,"wb");

if(fp==0)
return0;

//申请位图文件头结构变量,填写文件头信息

BITMAPFILEHEADERfileHead;

fileHead.bfType=0x4D42;//bmp类型

//bfSize是图像文件4个组成部分之和

fileHead.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+colorTablesize+lineByte*height;

fileHead.bfReserved1=0;

fileHead.bfReserved2=0;

//bfOffBits是图像文件前3个部分所需空间之和

fileHead.bfOffBits=54+colorTablesize;

//写文件头进文件

fwrite(&fileHead,sizeof(BITMAPFILEHEADER),1,fp);

//申请位图信息头结构变量,填写信息头信息

BITMAPINFOHEADERhead;

head.biBitCount=biBitCount;

head.biClrImportant=0;

head.biClrUsed=0;

head.biCompression=0;

head.biHeight=height;

head.biPlanes=1;

head.biSize=40;

head.biSizeImage=lineByte*height;

head.biWidth=width;

head.biXPelsPerMeter=0;

head.biYPelsPerMeter=0;

//写位图信息头进内存

fwrite(&head,sizeof(BITMAPINFOHEADER),1,fp);

//如果灰度图像,有颜色表,写入文件

if(biBitCount==8)
fwrite(pColorTable,sizeof(RGBQUAD),256,fp);

//写位图数据进文件

fwrite(imgBuf,height*lineByte,1,fp);

//关闭文件

fclose(fp);

return1;

}

//----------------------------------------------------------------------------------------
//以下为像素的读取函数
voiddoIt()
{

//读入指定BMP文件进内存

charreadPath[]="nv.BMP";

readBmp(readPath);

//输出图像的信息

cout<<"width="<<bmpWidth<<"height="<<bmpHeight<<"biBitCount="<<biBitCount<<endl;

//循环变量,图像的坐标

//每行字节数

intlineByte=(bmpWidth*biBitCount/8+3)/4*4;

//循环变量,针对彩色图像,遍历每像素的三个分量

intm=0,n=0,count_xiang_su=0;

//将图像左下角1/4部分置成黑色

ofstreamoutfile("图像像素.txt",ios::in|ios::trunc);

if(biBitCount==8)//对于灰度图像
{
//------------------------------------------------------------------------------------
//以下完成图像的分割成8*8小单元,并把像素值存储到指定文本中。由于BMP图像的像素数据是从
//左下角:由左往右,由上往下逐行扫描的
intL1=0;
inthang=63;
intlie=0;
//intL2=0;
//intfen_ge=8;
for(intfen_ge_hang=0;fen_ge_hang<8;fen_ge_hang++)//64*64矩阵行循环
{
for(intfen_ge_lie=0;fen_ge_lie<8;fen_ge_lie++)//64*64列矩阵循环
{
//--------------------------------------------
for(L1=hang;L1>hang-8;L1--)//8*8矩阵行
{
for(intL2=lie;L2<lie+8;L2++)//8*8矩阵列
{
m=*(pBmpBuf+L1*lineByte+L2);
outfile<<m<<"";
count_xiang_su++;
if(count_xiang_su%8==0)//每8*8矩阵读入文本文件
{
outfile<<endl;
}
}
}
//---------------------------------------------
hang=63-fen_ge_hang*8;//64*64矩阵行变换
lie+=8;//64*64矩阵列变换
//该一行(64)由8个8*8矩阵的行组成
}
hang-=8;//64*64矩阵的列变换
lie=0;//64*64juzhen
}
}

//doublexiang_su[2048];
//ofstreamoutfile("xiang_su_.txt",ios::in|ios::trunc);
if(!outfile)
{
cout<<"openerror!"<<endl;
exit(1);
}
elseif(biBitCount==24)
{//彩色图像
for(inti=0;i<bmpHeight;i++)
{
for(intj=0;j<bmpWidth;j++)
{
for(intk=0;k<3;k++)//每像素RGB三个分量分别置0才变成黑色
{
//*(pBmpBuf+i*lineByte+j*3+k)-=40;
m=*(pBmpBuf+i*lineByte+j*3+k);
outfile<<m<<"";
count_xiang_su++;
if(count_xiang_su%8==0)
{
outfile<<endl;
}
//n++;
}
n++;
}


}
cout<<"总的像素个素为:"<<n<<endl;
cout<<"----------------------------------------------------"<<endl;
}

//将图像数据存盘

charwritePath[]="nvcpy.BMP";//图片处理后再存储

saveBmp(writePath,pBmpBuf,bmpWidth,bmpHeight,biBitCount,pColorTable);

//清除缓冲区,pBmpBuf和pColorTable是全局变量,在文件读入时申请的空间

delete[]pBmpBuf;

if(biBitCount==8)
delete[]pColorTable;
}

voidmain()
{
doIt();
}

⑼ c语言数字图像处理怎么显示一张照片的像素值

#include <stdio.h>
#include <windows.h>
int main()
{
//变量
char title[255];//用于存放控制台窗口标题
HWND hwnd;//窗口的句柄,H:Handle
HDC hdc, hmemdc;//设备上下文句柄,DC:driver context
HBITMAP hbm;//图片的句柄
BITMAP bm;//图片结构体
RECT rect;//矩形 rectangle
//把控制台窗口调成100字符宽度,40行
system("mode con cols=100 lines=40");

//1.取得窗口的句柄
GetConsoleTitleA(title, 255);//获取控制台窗口的标题
hwnd = FindWindowA(NULL, title);//通过窗口标题取得该窗口的句柄
//获取窗口的高度和宽度
GetWindowRect(hwnd, &rect);
//2. 获取画笔
hdc = GetDC(hwnd);
/* if(!hdc)
printf("No val\n");
else
printf("have\n");
TextOutA(hdc, 300, 400, "Hello world", strlen("Hello world"));*/
hmemdc = CreateCompatibleDC(hdc);//创建一个兼容的DC
//3.加载图片
hbm = (HBITMAP)LoadImageA(NULL, "123.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
GetObject(hbm, sizeof(BITMAP), &bm);//得到图片信息
//4.把图片放入兼容DC中
SelectObject(hmemdc, hbm);

//5.在窗口上画出图片
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hmemdc, 0, 0, SRCCOPY);

DeleteObject(hbm);
DeleteObject(hmemdc);
ReleaseDC(hwnd, hdc);
return 0;
}

⑽ 怎么用C语言输出如下图形

#include<stdio.h>
void main()
{ int i,j,n=1;
for ( i=0;i<5;i++,printf("\n") ) //5行,每循环一次换行
for ( j=0;j<i+1;j++,n++ ) //每次循环分别输出1,2,3,4,5个数据
printf("%d ",n); //每次输出数据和一个空格,每输出一个数据数据自身加1
}