图像旋转后显示乱码
旋转前图像的宽高是4的倍数的矩形就没有问题;如果不是4的倍数,旋转就会显示出来乱码,我查了,说是扫描的行数要是4的倍数,要更改width的值,但更改了好几回,图片还是乱的。。。有人做过的,麻烦指点一下。多谢了
BITMAPINFO RGB24BitsBITMAPINFO;
ZeroMemory(&RGB24BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = width;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = height;//
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;
//use the function CreateDIBSection and SelectObject
//in order to get the bimap pointer : lpBitmapBits
HBITMAP directBmp = CreateDIBSection(hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO,
DIB_RGB_COLORS, (void **)&lpBitmapBits, NULL, 0);
HGDIOBJ previousObject = SelectObject(hMemDC, directBmp);
// copy the screen dc to the memory dc
BitBlt(hMemDC, 0, 0, width, height, hScrDC, 0, 0, SRCCOPY);
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4d42; //bmp
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + ((width*height)*3); ///3=(24 / 8)
typedef struct _MYRGB
{
char r;
char g;
char b;
}MyRGB;
ASSERT(sizeof(MyRGB) == 3);
MyRGB* pDes = (MyRGB*)malloc(width * height * 3 + 1);
if(pDes == NULL)
{
return;
}
memset(pDes,0,width * height * 3 + 1);
MyRGB* pSrc = (MyRGB* )lpBitmapBits;
if(nRotateType==1)//顺时针
{
for(int l = 0;l < width * height;l++)
{
int i = l/width;
int j = l%width;
pDes[(width - 1 - j) * height + i] = pSrc[i * width + j];
}
}
else //逆时针
{
for(int l = 0;l < width * height;l++)
{
int i = l/width;
int j = l%width;
pDes[j * height + height - 1 - i] = pSrc[i * width + j];
}
}
RGB24BitsBITMAPINFO.bmiHeader.biWidth = height;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = width;
[解决办法]
图片分辨率都是4的倍数哦。
[解决办法]
还不行?
如果是VC做的,把全套的代码发来给你调试一下