图片放大和缩小C#.net [英] Picture Zoom In and Zoom Out in C#.net
本文介绍了图片放大和缩小C#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们,
现在我在C#.net工作。我正在寻找C#.Net中的图片放大和缩小。我的属性是表格,图片框和工具条。在该工具条中,工具条中有3个按钮,一个是放大,另一个是缩小和关闭。我在图片框中插入一个JPEG文件。如果我单击放大button.Image将放大并单击Zoom Out按钮.Image将缩小如何执行此操作?请为这些问题找一个代码。请帮助我。
问候,
Lakshmi Narayanan.S
Hi friends,
Now I am working in C #.net .i am looking for Picture Zoom In and Zoom Out in C#.Net. My Properties are Form,Picture Box and Tool strip .In that Tool strip ,3 buttons are in that Tool strip one is Zoom In ,another One is Zoom Out and Close.i insert a JPEG File in picture box.if i click Zoom In button.Image will Zoom In.and click Zoom Out button .Image will Zoom Out how to do this?Please I want a Code for these issue.please help me.
Regards,
Lakshmi Narayanan.S
推荐答案
谷歌是你的朋友:好好经常拜访他。他可以比在这里发布问题更快地回答问题...
这里有一篇文章: PictureBox放大 [ ^ ] - 你会发现,如果你曾尝试过基本的谷歌......
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
There is an article here: PictureBox Zoom[^] - which you would have found, if you had tried even a basic google...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Image imgOriginal;
private void Form1_Load(object sender, EventArgs e)
{
// set Slider Attributes
zoomSlider.Minimum = 1;
zoomSlider.Maximum = 5;
zoomSlider.SmallChange = 1;
zoomSlider.LargeChange = 1;
zoomSlider.UseWaitCursor = false;
// reduce flickering
this.DoubleBuffered = true;
}
public Image PictureBoxZoom(Image img, Size size)
{
imgOriginal = Image.FromFile(openFileDialog1.FileName);
Bitmap bm = new Bitmap(imgOriginal, Convert.ToInt32(imgOriginal.Width * size.Width), Convert.ToInt32(imgOriginal.Height * size.Height));
Graphics grap = Graphics.FromImage(bm);
//grap.InterpolationMode = InterpolationMode.HighQualityBicubic;
return bm;
}
private void zoomSlider_Scroll(object sender, EventArgs e)
{
if (zoomSlider.Value > 0)
{
picBox.Image = null;
picBox.Image = PictureBoxZoom(imgOriginal, new Size(zoomSlider.Value, zoomSlider.Value));
}
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
DialogResult res = MessageBox.Show("Message", "Try", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes)
{
string imagepath = openFileDialog1.FileName;
picBox.ImageLocation = imagepath;
}
else
{
MessageBox.Show("picture cancelled", "message");
}
}
}
}
放大:
pictureBox1.Top =(int)(pictureBox1.Top - (pictureBox1.Height * 0.025));
pictureBox1.Left =(int)(pictureBox1 .Left - (pictureBox1.Width * 0.025));
pictureBox1.Height =(int)(pictureBox1.Height +(pictureBox1.Height * 0.05));
pictureBox1 .Width =(int)(pictureBox1.Width +(pictureBox1.Width * 0.05));
缩小:
pictureBox1.Top =(int)(pictureBox1.Top +(pictureBox1.Height * 0.025));
pictureBox1.Left =(int)(pictureBox1.Left +(pictureBox1。宽度* 0.025));
pictureBox1.Height =(int)(pictureBox1.Height - (pictureBox1.Height * 0.05));
pictureBox1.Width =(int) (pictureBox1.Width - (pictureBox1.Width * 0.05));
For Zooming In :
pictureBox1.Top= (int)(pictureBox1.Top - (pictureBox1.Height * 0.025));
pictureBox1.Left = (int)(pictureBox1.Left - (pictureBox1.Width * 0.025));
pictureBox1.Height = (int)(pictureBox1.Height + (pictureBox1.Height* 0.05));
pictureBox1.Width = (int)(pictureBox1.Width + (pictureBox1.Width * 0.05));
For Zooming Out :
pictureBox1.Top = (int)(pictureBox1.Top + (pictureBox1.Height * 0.025));
pictureBox1.Left = (int)(pictureBox1.Left + (pictureBox1.Width * 0.025));
pictureBox1.Height = (int)(pictureBox1.Height - (pictureBox1.Height* 0.05));
pictureBox1.Width = (int)(pictureBox1.Width - (pictureBox1.Width * 0.05));
这篇关于图片放大和缩小C#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文