?? testdlg.cpp
字號:
// TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Mybole.h"
#include "TestDlg.h"
#include <stdio.h>
#include <stdlib.h>
#define Headsize 54
int m,n,cow_num,rol_num, flag_num;
long width_old,height_old;
unsigned char header[54];
unsigned char *image;
BITMAP bm;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/************************************************************
BITMAP * LoadBitmapFile(char* FileName, int x, int y, HWND hwnd)
加載一張位圖的信息,并返回一個位圖的指針********************
*************************************************************/
BITMAP * LoadBitmapFile(char* FileName, int x, int y, HWND hwnd)
{
HDC hdc = GetDC(hwnd);
HANDLE BitHandle;
BitHandle = (HBITMAP)LoadImage(NULL, FileName, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
if(BitHandle == NULL)
{
MessageBox(0, "加載指定的位圖文件出錯", "程序錯誤!",
MB_ICONERROR | MB_SYSTEMMODAL | MB_OK);
return NULL;
}
HDC dc = CreateCompatibleDC(hdc);
SelectObject(dc, BitHandle);
GetObject(BitHandle, sizeof(BITMAP), &bm);
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, dc, 0,0, SRCCOPY);
CPoint m_pt;
// m_pt.x=x+bm.bmWidth+num1;
//m_pt.y=y+num2;
BitBlt(hdc, m_pt.x, m_pt.y, bm.bmWidth, bm.bmHeight, dc, 0,0, SRCCOPY);
ReleaseDC(hwnd, hdc);
return(&bm);
}
unsigned char * bmp_read( const char *filename)
{
// unsigned char *image;
char fname_bmp[128];
FILE *fp;
sprintf(fname_bmp, "%s.bmp", filename);
if (!(fp = fopen(fname_bmp, "rb")))
return NULL;
fseek(fp,0,SEEK_SET);
fread(header,sizeof(unsigned char),Headsize,fp);
//獲得文件寬度
width_old=header[18];
width_old+=(header[19]<<8);
width_old+=(header[20]<<16);
width_old+=(header[21]<<24);
// printf("the width_old of the picture %d\n",width_old);
//獲得文件高度
height_old= header[22];
height_old+=(header[23]<<8);
height_old+=(header[24]<<16);
height_old+=(header[25]<<16);
// printf("the height_old of the picture %d\n",height_old);
image = (unsigned char *)malloc(width_old * height_old*2);
if (image == NULL)
return NULL;
fread(image, sizeof(unsigned char), width_old * height_old*2, fp);
// AfxMessageBox("the programe in the read file");
fclose(fp);
return image;
}
int bmp_write(unsigned char *image)
{
FILE *fp[65];
char fname_bmp[128];
long width=m, height=n;
// long data_size;
long file_size = (width) * (height)*2+Headsize;
int i=0,j,k,num1,num2,flag=0,temp1,temp2;
j=width_old/m;
k=height_old/n;
cow_num=j; //行數目
rol_num=k; //列數目
if(j==0) {width=width_old; cow_num=1;}
if(k==0) {height=height_old; rol_num=1;}
//修改頭文件數據
//修改文件大小
header[2] = (unsigned char)(file_size &0x000000ff);
header[3] = (unsigned char)((file_size >> 8) & 0x000000ff);
header[4] = (unsigned char)((file_size >> 16) & 0x000000ff);
header[5] = (unsigned char)((file_size >> 24) & 0x000000ff);
//修改文件寬度
header[18] = (unsigned char)(width & 0x000000ff);
header[19] = (unsigned char)((width >> 8) &0x000000ff);
header[20] = (unsigned char)((width >> 16) &0x000000ff);
header[21] = (unsigned char)((width >> 24) &0x000000ff);
//修改文件高度
header[22] = (unsigned char)(height &0x000000ff);
header[23] = (unsigned char)((height >> 8) &0x000000ff);
header[24] = (unsigned char)((height >> 16) &0x000000ff);
header[25] = (unsigned char)((height >> 24) &0x000000ff);
//修改文件數據大小
/* data_size=width*height*2;
header[34] = (unsigned char)(data_size &0x000000ff);
header[35] = (unsigned char)((data_size >> 8) &0x000000ff);
header[36] = (unsigned char)((data_size >> 16) &0x000000ff);
header[37] = (unsigned char)((data_size >> 24) &0x000000ff);*/
if((width_old%m==0)&&(height_old%n==0))
{
flag_num=j*k; //flag_num表示可以將小屏幕分成多少份.
cow_num=j; //用m記錄每一行的數據的個數.
rol_num=k; //用n記錄每一列的數據的個數.
}
else
{
if(width_old%m)
{
flag_num=(j+1)*k;
cow_num=j+1;
}
if(height_old%n)
{
flag_num=j*(k+1);
rol_num=k+1;
}
if((width_old%m)&&(height_old%n))
{
flag_num=(j+1)*(k+1);
cow_num=j+1;
rol_num=k+1;
}
}
for(flag=0;flag<flag_num;flag++)
{
sprintf(fname_bmp, "%s_%d.bmp", "1007",flag);
if (!(fp[flag] = fopen(fname_bmp, "wb+")))
return -1;
fseek(fp[flag],0,SEEK_SET);
fwrite(header, sizeof(unsigned char), Headsize, fp[flag]); //所有文件都按需要截取的格式寫頭文件信息。
}
flag=0; //準備寫第一個文件。
if(flag_num==1)
{
fwrite(image, sizeof(unsigned char), width_old*height_old*2, fp[flag]); //BMP圖片數據信息的填寫
}
else
{
if((width_old%m==0)&&(height_old%n==0))
{
for(temp2=0;temp2<k;temp2++) //需要截取的小屏的列數超過1時,即分屏分成至少K行數目的小屏,進行按行讀取的形式.且前面的K-1行的數據都是完整的一小屏數據.只有最后一行的屏幕可能會出現誤差需要校正.
{
for (i=0;i<n;i++) //寫一排小屏幕的數據
{
for(temp1=0;temp1<j;temp1++)
{
fwrite(image, sizeof(unsigned char), width*2, fp[flag]); //BMP圖片數據信息的填寫
image=image+width*2;
flag++;
}
flag=flag-j;
}
flag=flag+j;
}
}
if(width_old%width) //當行不能整行截取時.
{
num1=width_old%width;
//printf("the size of the nomal file is %x\n",file_size);
//修改最每一行的最后一個文件寬度
num1=width_old%width;
header[18] = (unsigned char)(num1 & 0x000000ff);
header[19] = (unsigned char)((num1 >> 8) &0x000000ff);
header[20] = (unsigned char)((num1 >> 16) &0x000000ff);
header[21] = (unsigned char)((num1 >> 24) &0x000000ff);
//修改文件大小
file_size = (num1) * (height)*2+Headsize;
//修改文件大小
header[2] = (unsigned char)(file_size &0x000000ff);
header[3] = (unsigned char)((file_size >> 8) & 0x000000ff);
header[4] = (unsigned char)((file_size >> 16) & 0x000000ff);
header[5] = (unsigned char)((file_size >> 24) & 0x000000ff);
//printf("the size of the last file is %x\n",file_size);
for(temp1=0;temp1<k;temp1++)
{
flag=(temp1+1)*(j+1)-1;
fseek(fp[flag],0,SEEK_SET);
fwrite(header, sizeof(unsigned char), Headsize, fp[flag]);
}
flag=0;
//printf("the file of heade has been deal success\n");
for(temp2=0;temp2<k;temp2++) //需要截取的小屏的列數超過1時,即分屏分成至少K行數目的小屏,進行按行讀取的形式.且前面的K-1行的數據都是完整的一小屏數據.只有最后一行的屏幕可能會出現誤差需要校正.
{
for (i=0;i<n;i++) //寫一排小屏幕的數據
{
for(temp1=0;temp1<j;temp1++)
{
fwrite(image, sizeof(unsigned char), width*2, fp[flag]); //BMP圖片數據信息的填寫
image=image+width*2;
flag++;
}
fwrite(image, sizeof(unsigned char), num1*2, fp[flag]); //BMP圖片數據信息的填寫
image=image+num1*2;
flag=flag-j;
}
flag=flag+j+1;
}
}
if(width_old%width==0) num1=width;
if(height_old%height)
{
//修改文件寬度
header[18] = (unsigned char)(width & 0x000000ff);
header[19] = (unsigned char)((width >> 8) &0x000000ff);
header[20] = (unsigned char)((width >> 16) &0x000000ff);
header[21] = (unsigned char)((width >> 24) &0x000000ff);
// printf("%d\t%d\t%d\t%d\n",header[18],header[19],header[20], header[21]);
num2=height_old%height;
header[22] = (unsigned char)(num2 &0x000000ff);
header[23] = (unsigned char)((num2 >> 8) &0x000000ff);
header[24] = (unsigned char)((num2 >> 16) &0x000000ff);
header[25] = (unsigned char)((num2 >> 24) &0x000000ff);
file_size = (width) * (num2)*2+Headsize;//修改文件大小
// printf("the width of the last row picture is %d\n",width);
// printf("the size of width) * (num2file is %x\n",file_size);
//修改文件大小
header[2] = (unsigned char)(file_size &0x000000ff);
header[3] = (unsigned char)((file_size >> 8) & 0x000000ff);
header[4] = (unsigned char)((file_size >> 16) & 0x000000ff);
header[5] = (unsigned char)((file_size >> 24) & 0x000000ff);
//printf("the size of the last file is %x\n",file_size);
temp2=flag;
printf("flag=%d\n",flag);
flag=flag_num-cow_num;
for(temp1=0;temp1<j;temp1++)
{
fseek(fp[flag],0,SEEK_SET);
fwrite(header, sizeof(unsigned char), Headsize, fp[flag]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -