1.c ͼ?像处???Դ??
2.c++图像模糊处理
3.用C语言画一个哆啦A梦_附源码
4.纯Cè¯è¨å®ç°å¾åå¤çï¼
c ͼ????Դ??
#include <windows.h>
//读bmp需要两个结构
#pragma pack(push, enter_defBM, 1) //指定内存对齐单位为1。
typedef struct tagBmpFileHeader
{
WORD bfType; // 文件类型 BM
DWORD bfSize; // 文件大小
WORD bfReserved1; // 保留字
WORD bfReserved2; // 保留字
DWORD bfOffBits; // 位图的理源数据信息离文件头的偏移量
} BFH;
typedef struct tagBmpImgHeader
{
DWORD biSize; // 表示本结构的大小,0X
LONG biWidth; // 位图的像处宽度
LONG biHeight; // 位图的高度
WORD biPlanes; // 位面数永远为1
WORD biBitCount; // 位图的位数
DWORD biCompression; // 压缩类型
DWORD biSizeImage; // 表示位图数据区域的大小
LONG biXPelsPerMeter; // 表示显示设备的水平分辨率
LONG biYPelsPerMeter; // 表示显示设备的垂直分辨率
DWORD biClrUsed; // 实际使用的颜色数目
DWORD biClrImportant; // 重要的颜色数量
} BIH;
#pragma pack(pop, enter_defBM) //恢复默认内存对齐单位。
#define HDIB HANDLE // 位图句柄
DWORD WINAPI DIBNumColors(BYTE * data)
{
WORD wBitCount;
DWORD dwClrUsed = ((BIH *)data)->biClrUsed;
if (dwClrUsed != 0) return (WORD)dwClrUsed;
wBitCount = ((BIH *)data)->biBitCount;
return 1 << wBitCount;
}
WORD WINAPI PaletteSize(BYTE * data)
{
return (WORD)(::DIBNumColors(data) * sizeof(RGBQUAD));
}
BYTE * WINAPI FindDIBBits(BYTE * data)
{
return (data + *(DWORD *)data + ::PaletteSize(data));
}
// 获取Bmp的理源全网通游戏源码宽度
DWORD FAR DIBWidth(const BYTE * data)
{
BIH * pbmi;
pbmi = (BIH *)data;
if(pbmi->biSize == sizeof(BIH)) return pbmi->biWidth;
else return -1;
}
// 获取Bmp的高度
DWORD FAR DIBHeight(const BYTE * data)
{
BIH * pbmi;
pbmi = (BIH *)data;
if(pbmi->biSize == sizeof(BIH)) return pbmi->biHeight;
else return -1;
}
// 从文件读取Bmp图像数据
HDIB WINAPI ReadDIBFile(FILE * fp)
{
BFH bmf;
HDIB hDIB;
BYTE * pData;
rewind(fp);
if(fread(&bmf, sizeof(BFH), 1, fp) != 1) return NULL; // 文件读取错误
if(bmf.bfType != ) return NULL; // 文件类型错误
hDIB = (HDIB) ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, bmf.bfSize); // 为DIB分配内存
if (hDIB == 0) return NULL; // 内存分配失败。
pData = (BYTE *)::GlobalLock((HGLOBAL) hDIB); // 锁定
if(fread(pData,像处 1, bmf.bfSize - sizeof(BFH), fp) != (bmf.bfSize - sizeof(BFH))) // 文件读取错误
{
::GlobalUnlock((HGLOBAL) hDIB); // 解除锁定
::GlobalFree((HGLOBAL) hDIB); // 释放内存
return NULL;
}
::GlobalUnlock((HGLOBAL) hDIB); // 解除锁定
return hDIB; // 返回DIB句柄
}
BOOL WINAPI PaintDIB(HDC hDC, int posX, int posY, HDIB hDIB)
{
BYTE * pDIBHd; // BITMAPINFOHEADER指针
BYTE * pDIBBits; // DIB象素指针
BOOL bSuccess = FALSE; // 成功标志
HPALETTE hPal = NULL; // DIB调色板
//HPALETTE hOldPal = NULL; // 以前的调色板
if (hDIB == NULL) return FALSE; // 判断DIB对象是否为空
pDIBHd = (BYTE *) ::GlobalLock((HGLOBAL) hDIB); // 锁定DIB
pDIBBits = ::FindDIBBits(pDIBHd); // 找到DIB图像象素起始位置
::SetStretchBltMode(hDC, COLORONCOLOR); // 设置显示模式
// 调用SetDIBitsToDevice()来绘制DIB对象
bSuccess = ::SetDIBitsToDevice(hDC, // hDC
posX, posY,
((BIH *)pDIBHd)->biWidth, // nDestWidth
((BIH *)pDIBHd)->biHeight, // nDestHeight
0, // SrcX
0, // SrcY
0, // nStartScan
(WORD)DIBHeight(pDIBHd), // nNumScans
pDIBBits, // lpBits
(LPBITMAPINFO)pDIBHd, // lpBitsInfo
DIB_RGB_COLORS); // wUsage
::GlobalUnlock((HGLOBAL) hDIB); // 解除锁定
return bSuccess;
}
// 打印位图信息
VOID WINAPI PrintDIBInfo(HDIB hDIB)
{
BYTE * pDIBHd = (BYTE *)::GlobalLock((HGLOBAL) hDIB);
BIH * pbmi = (BIH *)pDIBHd;
const char *lp[] =
{
"位图信息长度: %d\n",
"位图图像大小: %dx%d\n",
"位面数:%d\n",
"位图颜色深度: %d\n",
"位图数据压缩类型: %d\n",
"位图数据区域大小: %d\n",
"位图分辨率: 水平 %d dpi, 垂直 %d dpi\n",
};
printf("Windows V3 cBitmapInfoHeader 信息\n\n");
printf(lp[0], pbmi->biSize);
printf(lp[1], pbmi->biWidth, pbmi->biHeight);
printf(lp[2], pbmi->biPlanes);
printf(lp[3], pbmi->biBitCount);
printf(lp[4], pbmi->biCompression);
printf(lp[5], pbmi->biSizeImage);
printf(lp[6], (LONG)(pbmi->biXPelsPerMeter * 0.f + 0.5f), (LONG)(pbmi->biYPelsPerMeter * 0.f + 0.5f));
::GlobalUnlock((HGLOBAL) hDIB); // 解除锁定
}
int main(int argc, char* argv[])
{
HDIB x;
FILE * fp = fopen("1.bmp", "rb");
if(fp==NULL) return -1;
x = ReadDIBFile(fp);
printf("DIB handle %u", x);
PaintDIB(GetDC(NULL), 0, 0, x);
PrintDIBInfo(x);
return 0;
}
c++图像模糊处理
#include <stdio.h>
int main()
{
int m, j, n, idx;
char c;
scanf("%d %d", &m, &n);
char *p = (char*)malloc(m * n);
char *q = (char*)malloc(m * n);
for(int i=0;i<n;i++)
{
j = 0;
while((c=getchar())!='\n')
{
if(isdigit(c))
{
ungetc(c,stdin);
scanf("%c",&p[i * m+ j]);
++ j;
if(j == m)
break;
}
}
}
memcpy(p, q, m*n);
for(int i=1;i<n-1;i++)
{
for(j=1;j<m-1;j++)
{
idx=i*m+j;
q[idx]=(p[idx-m]+p[idx-1]+p[idx+1]+p[idx+m]) / 4;
}
}
for(int i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%c ", p[i*m+n]);
}
printf("\n");
}
}
用C语言画一个哆啦A梦_附源码
// 通过C语言与Windows API,成功绘制出哆啦A梦的理源小鱼网 源码图像,并附上源代码示例。像处
以下是理源用于实现这一目标的代码:
c
#include
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
static TCHAR szAppName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
// 窗口风格设置
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"),像处 szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT("Windows"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, , , NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HPEN hBlackPen, hOldPen, hWhite2Pen;
HBRUSH hWhiteBrush, hOldBrush, hBlackBrush, hRedBrush, hYellowBrush;
static HBRUSH hBlueBrush, blue_brush, green_brush;
static HPEN hBlue3Pen, blue_pen, green_pen;
POINT pxRightHand[4], pxiLeftHand[4];
int xCursor, yCursor;
POINT point;
switch (message) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
// 在窗口上写字
Rectangle(hdc, rect.right / 2 - , 5, rect.right / 2 - , );
Rectangle(hdc, rect.right / 2 + , 5, rect.right / 2 + , );
TextOut(hdc, rect.right/2 -, , L"画蓝色哆啦A梦", 7);
TextOut(hdc, rect.right/2 + , , L"画绿色哆啦A梦", 7);
// 绘制哆啦A梦各个部位
// 绘制头部、脸、理源眼睛、像处瞳孔、理源鼻子、像处沙沙网源码嘴巴、理源胡子、像处身体、火影堂 源码肚子、项圈、铃铛、us aspx源码百宝袋、腿、脚掌、手臂与手掌等细节
// 绘制哆啦A梦的整体结构与细节
// 绘制哆啦A梦的各个部分
// 结束绘制
EndPaint(hwnd, &ps);
break;
// 其他消息处理
// 更多消息处理逻辑
}
return 0;
}
纯Cè¯è¨å®ç°å¾åå¤çï¼
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define ONE
#define ZERO 0
/
*typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
*/
void main (int argc,char *argv[])
{
FILE *fi,*fo;//I/O file
char fin[],fon[];//I/O file name
unsigned char **ri,**ro;
unsigned char buff;
long w,h;
int t;
int i,j;
if(argc<3)
{
printf("orginfile name:");
scanf("%s",fin);
printf("resultfile name:");
scanf("%s",fon);
}else{
sscanf(argv[1],"%s",fin);
sscanf(argv[2],"%s",fon);
}
if(argc==4)
sscanf(argv[4],"%d",&t);
else{
printf("theshold [0,]:");
scanf("%d",&t);
}
if (((fi=fopen(fin,"rb"))==NULL)||((fo=fopen(fon,"wb"))==NULL))
{
puts("\nfile open failed");
return;
}
fseek(fi,L,SEEK_SET);
fread(&w,sizeof(long),1,fi);
fread(&h,sizeof(long),1,fi);
fseek(fi,0L,SEEK_SET);
ri=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ri+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
ro=(unsigned char **)malloc(sizeof(unsigned *)*h);
for (i=0;i<h;i++)
*(ro+i)=(unsigned char *)malloc(sizeof(unsigned)*w);
//åé 失败åæèªè´!
for (i=0;i<;i++){
fread(&buff,sizeof(buff),1,fi);
fwrite(&buff,sizeof(buff),1,fo);}
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fread(*(ri+i)+j,sizeof(unsigned char),1,fi);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
*(*(ro+i)+j)=((*(*(ri+i)+j)<=t)?ZERO:ONE);
for (i=0;i<h;i++)
for (j=0;j<w;j++)
fwrite(*(ro+i)+j,sizeof(unsigned char),1,fo);
fclose(fo);
}