M
mrai rasouli
Guest
void CMRSMATH1Dlg:icturecuter(TCHAR *source, TCHAR *destination)
{
CFile f1,f2;
int width, height,gap,gap1;
int m1 = 1, m2 = 0;//m1 is width cut m2 height cut
int removeheightmode = removefrombottom;//enum
int removewidthmode= removefromright;//enum
BITMAPINFOHEADER Info;
BITMAPFILEHEADER bFileHeader;
f1.Open(source, CFile::modeRead | CFile::typeBinary);
f2.Open(destination, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary);
f1.Read(&bFileHeader, sizeof(BITMAPFILEHEADER));
f1.Read(&Info, sizeof(BITMAPINFOHEADER));
width = Info.biWidth;
height = Info.biHeight;
// Info.biSizeImage= ((width * 24 + 31) / 32) * 4 * height;
gap=(Info.biSizeImage - (width*height*3)) / height;
int size1 = ((((width - m1) * 24 + 31)&~31) / 32) * 4 * (height - m2);
int size2= ((((width) * 24 + 31) / 32)&~31) * 4 * (height);
gap1 =((size1) - ((width - m1)*(height - m2) * 3)) / (height- m2);
BYTE *b = (BYTE *)GlobalAlloc(GPTR,(width-m1) * 3);
bFileHeader.bfOffBits= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bFileHeader.bfSize = bFileHeader.bfOffBits + size1;
Info.biSizeImage = size1;
Info.biWidth = width - m1;
Info.biHeight = height - m2;
f2.Write(&bFileHeader,sizeof(BITMAPFILEHEADER));
f2.Write(&Info, sizeof(BITMAPINFOHEADER));
BYTE alpha = 0;
BYTE ch;
//deducted height+width-1
if (removeheightmode == removefrombottom)
{
for (int i = 0;i < m2;i++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i<gap + (m1 * 3);i++)
{//above is below
f1.Read(&ch, 1);
//rcount++;
}
}
}
if (removewidthmode == removefromleft)
{
for (int y = 0;y < height - m2;y++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, m1 * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i < gap;i++)
{
f1.Read(&ch, 1);
}
f2.Write(b, (width - m1) * 3);
for (int i = 0;i < gap1;i++)
f2.Write(&alpha, 1);
}
}
else
{
for (int y = 0;y < height - m2;y++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i < gap + (m1 * 3);i++)
{
f1.Read(&ch, 1);
}
f2.Write(b, (width - m1) * 3);
for (int i = 0;i < gap1;i++)
f2.Write(&alpha, 1);
}
}
//rcount = count + (height - 1)*gap1+gap+(width+height-1)*3;
GlobalFree(b);
f1.Close();
f2.Close();
}
Continue reading...
{
CFile f1,f2;
int width, height,gap,gap1;
int m1 = 1, m2 = 0;//m1 is width cut m2 height cut
int removeheightmode = removefrombottom;//enum
int removewidthmode= removefromright;//enum
BITMAPINFOHEADER Info;
BITMAPFILEHEADER bFileHeader;
f1.Open(source, CFile::modeRead | CFile::typeBinary);
f2.Open(destination, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary);
f1.Read(&bFileHeader, sizeof(BITMAPFILEHEADER));
f1.Read(&Info, sizeof(BITMAPINFOHEADER));
width = Info.biWidth;
height = Info.biHeight;
// Info.biSizeImage= ((width * 24 + 31) / 32) * 4 * height;
gap=(Info.biSizeImage - (width*height*3)) / height;
int size1 = ((((width - m1) * 24 + 31)&~31) / 32) * 4 * (height - m2);
int size2= ((((width) * 24 + 31) / 32)&~31) * 4 * (height);
gap1 =((size1) - ((width - m1)*(height - m2) * 3)) / (height- m2);
BYTE *b = (BYTE *)GlobalAlloc(GPTR,(width-m1) * 3);
bFileHeader.bfOffBits= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bFileHeader.bfSize = bFileHeader.bfOffBits + size1;
Info.biSizeImage = size1;
Info.biWidth = width - m1;
Info.biHeight = height - m2;
f2.Write(&bFileHeader,sizeof(BITMAPFILEHEADER));
f2.Write(&Info, sizeof(BITMAPINFOHEADER));
BYTE alpha = 0;
BYTE ch;
//deducted height+width-1
if (removeheightmode == removefrombottom)
{
for (int i = 0;i < m2;i++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i<gap + (m1 * 3);i++)
{//above is below
f1.Read(&ch, 1);
//rcount++;
}
}
}
if (removewidthmode == removefromleft)
{
for (int y = 0;y < height - m2;y++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, m1 * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i < gap;i++)
{
f1.Read(&ch, 1);
}
f2.Write(b, (width - m1) * 3);
for (int i = 0;i < gap1;i++)
f2.Write(&alpha, 1);
}
}
else
{
for (int y = 0;y < height - m2;y++)
{
memset(b, 0, (width - m1) * 3);
f1.Read(b, (width - m1) * 3);
for (int i = 0;i < gap + (m1 * 3);i++)
{
f1.Read(&ch, 1);
}
f2.Write(b, (width - m1) * 3);
for (int i = 0;i < gap1;i++)
f2.Write(&alpha, 1);
}
}
//rcount = count + (height - 1)*gap1+gap+(width+height-1)*3;
GlobalFree(b);
f1.Close();
f2.Close();
}
Continue reading...