aspect ratio of image crashing the program

我是研究僧i 提交于 2019-12-25 00:37:55

问题


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);

}

回答1:


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.



来源:https://stackoverflow.com/questions/17746156/aspect-ratio-of-image-crashing-the-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!