📄 newfile.cpp
字号:
/********************** COMAPI.CPP *******************************/
#include "stdafx.h"
#include <io.h>
#include <direct.h>
#include <afxext.h>
#include "comapi.h"
#include "fig2.h"
/***************************** fspace_1d **************************/
/* To allocation a 1_dimension dynamic array */
/*
void* WINAPI fspace_1d(WORD col,WORD length)
{
void *b;
b = (void *)calloc(length,col);
if (b==NULL){
// MessageBox("Memory error 1");
exit(1);
}
return(b);
}
*/
/************* fspace_2d ***************************************/
/* To allocation a 2_dimension dynamic array */
void** WINAPI fspace_2d(WORD row,WORD col,WORD lenth)
{
int i;
void **b;
b = (void **)calloc(sizeof(void *),row);
if (b==NULL)
{
//MessageBox("Memory error 1");
exit(1);
}
for(i=0;i<row;i++)
{
b[i] = (void *)calloc(lenth,col);
if (b[i]==NULL)
{
//MessageBox("Memory error 2");
exit(1);
}
}
return(b);
}
/******************************* ffree_2d ****************************/
/* To free a 2_dimension dynamic array */
void WINAPI ffree_2d(void **a,WORD row)
{
int i;
for(i=0;i<row;i++) free(a[i]);
free(a);
}
//--copy dib data to 2-D array
unsigned char ** WINAPI DIBToArray(HDIB hDIB,WORD &wHeight,
WORD &wWidth)
{
WORD wNewWidth;
DWORD dwSize;
LPSTR lpDIBHdr;
LPSTR lpDIBBits;
unsigned char** uppImage;
lpDIBHdr=(LPSTR)::GlobalLock((HGLOBAL)hDIB);
lpDIBBits=::FindDIBBits(lpDIBHdr);
wHeight=(WORD)(::DIBHeight(lpDIBHdr));
wWidth=(WORD)(::DIBWidth(lpDIBHdr));
wNewWidth=(((wWidth*8)+31)/32)*4;
dwSize=(DWORD)wNewWidth*wHeight;
DWORD dwOffset=dwSize;
uppImage=(unsigned char**)fspace_2d(wHeight,wWidth,
sizeof(unsigned char));
for(WORD i=0;i<wHeight;i++){
dwOffset-=wNewWidth;
for(WORD j=0;j<wWidth;j++)
uppImage[i][j]=*(lpDIBBits+dwOffset+j);
}
/*/
for(WORD i=0;i<wHeight;i++){
for(WORD j=0;j<wWidth;j++)
uppImage[i][j]=*(lpDIBBits+(long)i*wWidth+j);
}
/*/
::GlobalUnlock((HGLOBAL)hDIB);
return(uppImage);
}
//copy a 2-D array to a dib data
void WINAPI ArrayToDIB(WORD wHeight,WORD wWidth,
unsigned char **Image,HDIB hDIB)
{
WORD wNewWidth;
DWORD dwSize;
LPSTR lpDIBHdr;
LPSTR lpDIBBits;
lpDIBHdr=(LPSTR)::GlobalLock((HGLOBAL)hDIB);
lpDIBBits=::FindDIBBits(lpDIBHdr);
wNewWidth=(((wWidth*8)+31)/32)*4;
dwSize=(DWORD)wNewWidth*wHeight;
DWORD dwOffset=dwSize;
for(WORD i=0;i<wHeight;i++){
dwSize-=wNewWidth;
for(WORD j=0;j<wWidth;j++)
*(lpDIBBits+dwSize+j)=Image[i][j];
}
/*/
for(WORD i=0;i<wHeight;i++){
for(WORD j=0;j<wWidth;j++)
*(lpDIBBits+(long)i*wWidth+j)=Image[i][j];
}
/*/
::GlobalUnlock((HGLOBAL)hDIB);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -