我在放大图片框Picture Control中显示的图片时遇到了问题。预期结果类似于以下链接:可滚动、可缩放和可伸缩的图片框。图片在picturebox中放大。注意,图片框被放大。
但是,这可以在.NET Framework2.0中实现。我在互联网上搜索过一些信息,但是没有一个使用Visual的C/C++ Windows。当我在Visual Picture Control 2010的C++窗体上工作时,如何在picturebox C++中缩放图片。谢谢你的回复。
发布于 2014-09-30 10:00:56
如果没有任何源代码,就很难进行注释。StackOverflow用于解决问题;我们可以对开始的代码进行故障排除,并使其正常工作,在此过程中,我们还可以微调设计。
总之,我想给出一些建议:
StretchBlt是一个功能强大的API,可以用来实现。详情请参见MSDN文档。CBitmap、CImage、Gdiplus::Image。
每个人都有自己的优点和缺点。
如果要支持透明图像/PNG,最好选择CImage或Gdiplus::Image。你可以在这里得到足够的信息:
CBitmap
CImage
图形:图像希望这能给你一些开场白。
发布于 2016-08-08 11:49:28
我也面临过同样的问题,我搜索了很多次,但是没有在cpp中找到解决方案(在c#和VB中可以免费获得)。最后,我决定自己来实现它。如果您的图像大小大于图片框,那么只有1级缩放(原始图像大小),您可以使用我的实现。我会帮你实现的。在当前的实现中,如果您做鼠标左击,它将ZoomIn,如果您执行鼠标右键单击,它将ZoomOut。
假设您已经读取了图像文件(.png、.jpg、.bmp、.)在bmpPicture中。
位图^bmpPicture = gcnew (StrFilename);//如果不是,它可以帮助
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
MouseEventArgs ^ms = (MouseEventArgs^)e;
if (ms->Button == System::Windows::Forms::MouseButtons::Left)
{
int pbx = ms->X;
int pby = ms->Y;
int img_x = (pbx * mwidth / pbwidth * 1.0f);
int img_y = (pby * mheight / pbheight * 1.0f);
pictureBox1->Location = System::Drawing::Point(pbx - img_x, pby - img_y);
pictureBox1->SizeMode = PictureBoxSizeMode::AutoSize;
pictureBox1->Image = bmpPicture;
}
else if(ms->Button == System::Windows::Forms::MouseButtons::Right)
{
int pbx = ms->X;
int pby = ms->Y;
pictureBox1->Location = System::Drawing::Point(0, 0);
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
pictureBox1->Image = bmpPicture;
}
}
Hope this will help you...https://stackoverflow.com/questions/26056145
复制相似问题