Код (Text): if ((bi.biWidth%2)!=0) { buff_size-=-bi.biHeight*2; cout<<"Unalligning..."<<endl; tptr=tmp_buff; optr=out_buffer; for (int i=0;i<(-bi.biHeight);i++) { memcpy(tptr,optr,bi.biWidth*bi.biBitCount/8); optr+=(bi.biWidth*bi.biBitCount/8); optr+=2; tptr+=bi.biWidth*bi.biBitCount/8; } free (out_buffer); out_buffer=tmp_buff; cout<<"Unalligning...OK"<<endl; } */ После этого кода всё летит к чертям. Код (Text): BITMAPFILEHEADER bfh; BITMAPINFOHEADER bi; out_buffer=(byte*)malloc(buff_size); tmp_buff=(byte*)malloc(buff_size); fread_s(out_buffer,buff_size,sizeof(byte),buff_size,hBmpFile); Exceptions разные. Но именно при присутствии этого кода. Вот всё: Код (Text): int n; byte* optr; byte* tptr; int ret; BITMAPFILEHEADER bfh; BITMAPINFOHEADER bi; char fNameOut[MAX_PATH]; char fBmpName[MAX_PATH]; char* fBmpNamePtr; char t_dst[MAX_PATH]; char fChunkName[MAX_PATH]; int ch_size= NULL; DWORD key= NULL; int bmp_count= NULL; FILE* hOutFile= NULL; FILE* hBmpFile= NULL; FILE* hChunkFile= NULL; int iter= NULL; int t_ret= NULL; int bpp= NULL; int width_i= NULL; int height_i= NULL; int buff_size= NULL; byte* out_buffer= NULL; int all_size= NULL; byte* chunk_buff= NULL; byte* tmp_buff= NULL; const WORD sig= (WORD)0x4D42; memset(&bfh,0x00,sizeof(bfh)); memset(&bi,0x00,sizeof(bi)); cout<<"Gambler compiler 1.0"<<endl; cout<<"Be attentive, images must be 16 bit, 5-6-5 color format"<<endl; cout<<"and some size that original and have a minus height"<<endl; cout<<"Please specify images count: "; cin>>bmp_count; cout<<endl; if (bmp_count<=NULL) return NULL; cout<<"Input bitmap filename postfix: "; cin>>fBmpName; cout<<endl; cout<<"Input output file name: "; cin>>fNameOut; cout<<endl; fopen_s(&hOutFile,fNameOut,"w+b"); if (!hOutFile) return NULL; iter=0; while (iter<bmp_count) { _itoa_s(iter,t_dst,4,TEN_RADIX_SYSTEM); fBmpNamePtr=strcat((char *)t_dst,fBmpName); fopen_s(&hBmpFile,fBmpNamePtr,"rb"); if (!hBmpFile) return NULL; fread_s(&bfh,sizeof(bfh),sizeof(bfh),1,hBmpFile); if (bfh.bfType!=sig) return 0; fread_s(&bi,sizeof(bi),sizeof(bi),1,hBmpFile); if ((bi.biBitCount!=need_bpp)&& (bi.biPlanes!=1)&& (bi.biHeight>=0)) return NULL; n=0; if ((bi.biWidth%2)!=0) n=2; buff_size=-(bi.biWidth*bi.biHeight*(bi.biBitCount/8))+n*bi.biHeight; if (buff_size<=0) return NULL; fread_s(&red_mask,4,4,1,hBmpFile); if (red_mask!=0xF800) return 0; fread_s(&green_mask,4,4,1,hBmpFile); if (green_mask!=0x07E0) return 0; fread_s(&blue_mask,4,4,1,hBmpFile); if (blue_mask!=0x001F) return 0; cout<< "Reading "; cout<< (buff_size); cout<< " bytes of picture... "; cout<< (iter); cout<< endl; out_buffer=(byte*)malloc(buff_size); tmp_buff=(byte*)malloc(buff_size); fread_s(out_buffer,buff_size,sizeof(byte),buff_size,hBmpFile); cout<<"Read passed: OK!"<<endl; fclose(hBmpFile); /* if ((bi.biWidth%2)!=0) { buff_size-=-bi.biHeight*2; cout<<"Unalligning..."<<endl; tptr=tmp_buff; optr=out_buffer; for (int i=0;i<(-bi.biHeight);i++) { memcpy(tptr,optr,bi.biWidth*bi.biBitCount/8); optr+=(bi.biWidth*bi.biBitCount/8); optr+=2; tptr+=bi.biWidth*bi.biBitCount/8; } free (out_buffer); out_buffer=tmp_buff; cout<<"Unalligning...OK"<<endl; } */ all_size+=buff_size; fwrite(out_buffer,sizeof(BYTE),buff_size,hOutFile); cout<<"Write passed: OK!"<<endl; if ((bi.biWidth%2)!=0) { free(out_buffer); } else { free(out_buffer); free(tmp_buff); } iter++; }