崩溃的节目图像的长宽比 [英] aspect ratio of image crashing the program
问题描述
这里是code此code是当控制去诠释WindowRatio = WidthOf previewPane / HeightOf previewPane保持崩溃图像的长宽比;
谁能给想法,为什么?
INT WidthOf previewPane = RECTWIDTH(m_rcParent);
INT HeightOf previewPane = RECTHEIGHT(m_rcParent);INT ImageRatio = WidthOfImage / HeightOfImage;
INT WindowRatio = WidthOf previewPane / HeightOf previewPane;如果(WindowRatio> ImageRatio和放大器;&安培; WidthOf previewPane< WidthOfImage)
{
m_iFinalHeight = HeightOf previewPane;
m_iFinalWidth = m_iFinalHeight * ImageRatio;
的MessageBox(NULL,L1,长度错误,
MB_ICONERROR | MB_OK);
}
否则,如果(WindowRatio< ImageRatio&放大器;&安培; WidthOf previewPane< WidthOfImage)
{
m_iFinalWidth = WidthOf previewPane;
m_iFinalHeight = m_iFinalWidth / ImageRatio;
的MessageBox(NULL,L2,L错误,
MB_ICONERROR | MB_OK);
}
否则,如果(WindowRatio> ImageRatio和放大器;&安培; WidthOf previewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
的MessageBox(NULL,L3,长度错误,
MB_ICONERROR | MB_OK);}
否则,如果(WindowRatio< ImageRatio&放大器;&安培; WidthOf previewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
的MessageBox(NULL,L4,L错误,
MB_ICONERROR | MB_OK);}
该算法中的逻辑是正确的我终于发现,WidthOf previewPane和HeightOf previewPane = 0的,因为在我所编写的功能这code,最后被初始化,因此这2个没有初始化的时候,我调试他们,我通过把它们放在一个if条件,这将让控制里面去,如果他们的值不为0回避THID问题和它的工作好听。
看到这 -
如果(WidthOf previewPane = 0&安培;!&安培;!HeightOf previewPane = 0)
{
这里的条件...... }
和多数民众解决。
here is the code this code is to maintain the aspect ratio of the image it crashes when the control goes to int WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane; can anyone give idea why ??
int WidthOfPreviewPane = RECTWIDTH(m_rcParent);
int HeightOfPreviewPane = RECTHEIGHT(m_rcParent) ;
int ImageRatio = WidthOfImage / HeightOfImage;
int WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane;
if (WindowRatio > ImageRatio && WidthOfPreviewPane< WidthOfImage)
{
m_iFinalHeight = HeightOfPreviewPane;
m_iFinalWidth = m_iFinalHeight * ImageRatio;
MessageBox(NULL, L"1",L"Error",
MB_ICONERROR | MB_OK);
}
else if (WindowRatio < ImageRatio && WidthOfPreviewPane< WidthOfImage)
{
m_iFinalWidth = WidthOfPreviewPane;
m_iFinalHeight = m_iFinalWidth / ImageRatio;
MessageBox(NULL, L"2",L"Error",
MB_ICONERROR | MB_OK);
}
else if(WindowRatio > ImageRatio && WidthOfPreviewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
MessageBox(NULL, L"3",L"Error",
MB_ICONERROR | MB_OK);
}
else if(WindowRatio < ImageRatio && WidthOfPreviewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
MessageBox(NULL, L"4",L"Error",
MB_ICONERROR | MB_OK);
}
the logic of this algo is correct finally i found that WidthOfPreviewPane and HeightOfPreviewPane=0 its because the function in which i have written this code was initialized at last so these 2 were not initialized that time when i debugged them and i avoided thid problem by putting them in in a if condition which will let the control go inside if their value is not 0 and it worked nicely. see this-
if(WidthOfPreviewPane!= 0 && HeightOfPreviewPane!=0 )
{
conditions here......
}
and thats solved.
这篇关于崩溃的节目图像的长宽比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!