当我将设备从横向模式旋转到实时预览窗口的Portait模式时出现旋转和失真问题 [英] Rotation and Distortion issue when I rotate device from landscape mode to Portait mode for Live preview window
问题描述
我的相机应用程序容器大小为640x480,当我将设备保持在横向模式时,我有完美的图像(实时预览),当我旋转设备90/270时使用实时预览窗口进入纵向模式,图像变形
并且图像不旋转,我有Routines RotateImage90()和RotateImage270(),这两个例程我确实使用了TranslateTransform()和ScaleTransform()函数并使用DrawImage()绘制图像。
我的问题是:当我将设备从横向模式旋转到纵向模式时,图像不旋转,也会引入一些失真,下面两个例程是一个顺时针和反时钟旋转,
在横向模式下我有完美的图像640x480(容器尺寸与图像尺寸相同),而在纵向模式下,我的图像要小得多(失真),图像也不能旋转。我可以将它们用于实时预览窗口吗?赞赏。
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.
//顺时针肖像模式
void OrientationTransform :: RotateImage90(BYTE * data,int dataLength){
   //指向一个图像缓冲器副本操纵
//clockwise Portrait mode
void OrientationTransform::RotateImage90(BYTE* data, int dataLength) {
// Pointer to a image buffer copy for manipulation
              &NBSP ; BYTE * dataTemp;
BYTE *dataTemp;
dataTemp = new BYTE [dataLength];
memcpy(dataTemp,data,dataLength);
dataTemp = new BYTE[dataLength];
memcpy(dataTemp, data, dataLength);
BITMAPINFOHEADER波黑= m_videoInfo.bmiHeader;
              位图BMP2(bih.biWidth,bih.biHeight,m_stride,m_pixFmt,的DataTemp);
                BMP位图(bih.biWidth,bih.biHeight,m_stride,m_pixFmt,数据);
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);
          &NBSP ;    图形g(& bmp);
g.Clear(彩色::黑色);
Graphics g(&bmp);
g.Clear(Color::Black);
              &NBSP ; 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);
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);
                删除dataTemp;
}
delete dataTemp;
}
void OrientationTransform :: RotateImage270(BYTE * data,int dataLength)
  ; {
//指向用于操作的图像缓冲区副本的指针
BYTE *的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);
dataTemp = new BYTE[dataLength];
memcpy(dataTemp, data, dataLength);
BITMAPINFOHEADER bih = m_videoInfo.bmiHeader;
位图BMP2(bih.biWidth,bih.biHeight,m_stride,m_pixFmt,的DataTemp);
                BMP位图(bih.biWidth,bih.biHeight,m_stride,m_pixFmt,数据);
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);
          &NBSP ;    图形g(& bmp);
g.Clear(彩色::黑色);
Graphics g(&bmp);
g.Clear(Color::Black);
              &NBSP ; g.TranslateTransform( - (float)bmp2.GetWidth()/ 2,
  ;-( float)bmp2.GetHeight()/ 2);
g.TranslateTransform(-(float)bmp2.GetWidth() / 2,
-(float)bmp2.GetHeight() / 2);
g.ScaleTransform(bmp2.GetWidth()/ 2,bmp2.GetHeight()/ 2);
       g.RotateTransform(270);
g.TranslateTransform((浮点)bmp2.GetWidth()/ 2,(浮点)bmp2.GetHeight()/ 2);
       &NBSP ;       g.DrawImage(安培; BMP2,0,0);
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);
                删除dataTemp;
}
delete dataTemp;
}
推荐答案
您能否为您的问题提供更多背景信息?它是通用应用程序吗?为什么要手动旋转而不是依赖XAML?你可以问MediaCapture对象
旋转预览。
Could you provide more context to your question? Is it a Universal app? Why are you rotating it manually instead of relying on XAML? You can ask MediaCapture object to rotate preview for you.
这篇关于当我将设备从横向模式旋转到实时预览窗口的Portait模式时出现旋转和失真问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!