📄 myclass.cpp
字号:
#include "stdafx.h"
#include "MyClass.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//====================================================================
//====================================================================
//________________Classe Image______________________
Image::Image(int width0, int height0)
{
int i,j;
width=width0;
height=height0;
ng=(int **)calloc(width,sizeof(int *));
for (i=0;i<width;i++)
ng[i]=(int *)calloc(height,sizeof(int));
for (j=0;j<height;j++)
{
for (i=0; i<width;i++)
{
ng[i][j]=0;
}
}
}
//___________________________________________________________________
Image::~Image()
{
int i;
for (i=0; i<width; i++)
{
free(ng[i]);
}
free(ng);
}
//____________________________________________________________________
void Image::Write(char* filename)
{
FILE *fp;
fp=fopen(filename,"w+");
fprintf(fp,"P2\n%d %d\n%d\n",width,height,255);
for (int j=0;j<height;j++)
{
for (int i=0; i<width;i++)
{
fprintf(fp,"%d ",ng[i][j]);
}
fprintf(fp,"\n");
}
fclose(fp);
}
//____________________________________________________________________
void Image::copy(Image* im)
{
int i, j;
height=im->height;
width=im->width;
for (j=0;j<height;j++)
for (i=0;i<width;i++)
ng[i][j]=im->ng[i][j];
}
//____________________________________________________________________
Image::Image(char* filename)
{
FILE *fp;
char s[5];
int i,j;
fp=fopen(filename, "r+");
fscanf(fp,"%s %d %d %d", s,&width,&height,&i);
ng=(int**) malloc (width*sizeof(int*));
for(i=0;i<width;i++)
{
ng[i]=(int*) malloc (height*sizeof(int));
}
for(j=0;j<height;j++)
{
for(i=0;i<width;i++)
{
fscanf(fp, "%d",&ng[i][j]);
}
}
fclose(fp);
}
//_______________________________________________________
void Image::Afficher(CDC* dc, int x, int y)
{
int i,j;
for(i=0;i<height;i++)
for(j=0;j<width;j++)
dc->SetPixel(j+x,i+y,RGB(ng[j][i],ng[j][i],ng[j][i]));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -