缩放图像中心 [英] Zoom center of image

查看:41
本文介绍了缩放图像中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个放大/缩小图像的程序.

I create a program that zoom in/out an image.

但它不会缩放到中心.

我的图片框在面板中,代码是:

My picture box is in a panel and code is:

Image newImage = Image.FromFile("view.jpg");
pictureBox1.Width = (int)(newImage.Size.Width / ZoomLevel);
pictureBox1.Height = (int)(newImage.Size.Height / ZoomLevel);

Bitmap img = new Bitmap(newImage, 
                        (int)(newImage.Size.Width / ZoomLevel), 
                        (int)(newImage.Size.Height / ZoomLevel));
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.Image = img;

我在这里上传了一个示例项目.请下载这个

我使用 Visual Studio 2008、C#、.Net 3.5

I use Visual Studio 2008, C#, .Net 3.5

提前致谢.

推荐答案

我认为是因为你改变了图片框的大小.它居中,但我看不到它,因为你总是看到所有的图片.

I think it is because you change the size of the picturebox. it is centered but i can not see it because you always see all the picture.

尝试删除 2 行,更改图片框的宽度和高度,或将它们设置为常量,如 1 或 2 或...如果您希望它根据图片:

try to remove the 2 rows the change the width and hight of the picturebox or set them to be constant like 1 or 2 or... if you want to it to be according to the picture:

第一个选项:

Image newImage = Image.FromFile("view.jpg");
Bitmap img = new Bitmap(newImage, 
                        (int)(newImage.Size.Width / ZoomLevel), 
                        (int)(newImage.Size.Height / ZoomLevel));
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.Image = img;

第二个选项:

Image newImage = Image.FromFile("view.jpg");
pictureBox1.Width = (int)(newImage.Size.Width / 1);
pictureBox1.Height = (int)(newImage.Size.Height / 1);

Bitmap img = new Bitmap(newImage, 
                        (int)(newImage.Size.Width / ZoomLevel), 
                        (int)(newImage.Size.Height / ZoomLevel));
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.Image = img;

这篇关于缩放图像中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆