I have camera application with container size 640x480, when I keep Device in Landscape mode, I have perfect Image (live preview), when I rotate device 90 / 270 Degrees into Portrait mode with live preview window, the image gets distorted and also Image not rotating , I have Routines RotateImage90() and RotateImage270(), these Two routines I did use TranslateTransform() and ScaleTransform() function and use DrawImage() to draw the image.
my issue is: when I rotate device from Landscape mode to Portrait mode, image not rotating, also some distortion introduced, the below Two routines are the one to rotate clock-wise and anti-clock-wise,I have perfect image 640x480 in Landscape mode (container size is same as image size), whereas with Portrait mode, I have image is much smaller (distortion) , also Image not rotating. can I use these for live preview window? appreciated.
//clockwise Portrait mode
void OrientationTransform::RotateImage90(BYTE* data, int dataLength) {
// Pointer to a image buffer copy for manipulation
BYTE *dataTemp;
dataTemp = new BYTE[dataLength];
memcpy(dataTemp, data, dataLength);
BITMAPINFOHEADER bih = m_videoInfo.bmiHeader;
Bitmap bmp2(bih.biWidth, bih.biHeight, m_stride, m_pixFmt, dataTemp);
Bitmap bmp(bih.biWidth, bih.biHeight, m_stride, m_pixFmt, data);
Graphics g(&bmp);
g.Clear(Color::Black);
g.TranslateTransform(-(float)bmp2.GetWidth() / 2,
-(float)bmp2.GetHeight() / 2);
g.ScaleTransform(bmp2.GetWidth() / 2 , bmp2.GetHeight() / 2 );
g.RotateTransform(90);
g.TranslateTransform((float)bmp2.GetWidth() / 2, (float)bmp2.GetHeight() / 2);
g.DrawImage(&bmp2, 0, 0);
delete dataTemp;
}
void OrientationTransform::RotateImage270(BYTE* data, int dataLength)
{
// Pointer to a image buffer copy for manipulation
BYTE *dataTemp;
dataTemp = new BYTE[dataLength];
memcpy(dataTemp, data, dataLength);
BITMAPINFOHEADER bih = m_videoInfo.bmiHeader;
Bitmap bmp2(bih.biWidth, bih.biHeight, m_stride, m_pixFmt, dataTemp);
Bitmap bmp(bih.biWidth, bih.biHeight, m_stride, m_pixFmt, data);
Graphics g(&bmp);
g.Clear(Color::Black);
g.TranslateTransform(-(float)bmp2.GetWidth() / 2,
-(float)bmp2.GetHeight() / 2);
g.ScaleTransform(bmp2.GetWidth() / 2 , bmp2.GetHeight() / 2 );
g.RotateTransform(270);
g.TranslateTransform((float)bmp2.GetWidth() / 2, (float)bmp2.GetHeight() / 2);
g.DrawImage(&bmp2, 0, 0);
delete dataTemp;
}