All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
程序开发:ASP.NET热点问题解答14个_[Asp.Net教程]
如何在OS,X系统上配置Apache、PHP和MySQL_php资料_编程技术
使ASP.NET中的数据库操作变得简单_[Asp.Net教程]
ASP与ASP.NET互通COOKIES的一点经验_[Asp.Net教程]
ASP.NET实例:增强,GridView,控件的功能(二)_[Asp.Net教程]
SEO网站设计中不可忽略的细节_百度优化_seo学堂
菜鸟学习php一个月总结_[PHP教程]
在ASP.NET,2.0中建立站点导航层次_.net资料_编程技术
TABLE导入到EXCEL_[Asp.Net教程]
PHP脚本的8个技巧(8)PHP和XML_php资料_编程技术
Reading number is top 10 pictures
Summer is most suitable for young people to travel in China9
The real super beauty12
姑娘手慢了,已经走光了
漂亮的跳舞妹妹1
2012 national geographic daily picture3
Sora aoi mirror memorial classics3
NeedWallpaper14
8090后结婚的各种XX事
Japan sexy beauty passion photo
A man's favorite things4
Download software ranking
WebService在.NET中的实战应用教学视频 → 第4集
VC++6.0简体中文版
Eclipse 4.2.2 For Win32
好色的外科大夫
网页特效实例大全
Proficient in JavaScript
Unix video tutorial9
传奇私服架设教程
金山office2007
Prostitutes diary
qq published in(发表于) 2014/7/11 9:23:43 Edit(编辑)
C#教程:在GDI+中缩放图像

C#教程:在GDI+中缩放图像

C#教程:在GDI+中缩放图像

在GDI+中缩放图像

DrawImage为可重载方法,它的一种形式接收一个Bitmap对象和一个Rectangle结构。Rectangle矩形结构指定了绘图操作的目标,如果目标矩形的大小与原始图像的大小不同,原始图像将进行缩放,以适应目标矩形。

示例

缩放图像

本示例中,当程序运行时,单击【缩放图像】按钮,在窗体中从左向右依次绘制3幅图像,其中第1幅图为原始图像的缩小形式,第2幅图与原始图像大小相同,第3幅图为原始图像的放大形式。示例运行结果如图1所示。



图1 缩放图像

Form1窗体中,在【缩放图像】按钮的Click事件中定义3个Rectangle矩形结构,然后调用Graphics类的DrawImage方法,在窗体中根据已经定义的3个Rectangle矩形结构依次绘制3幅图像。【缩放图像】按钮的Click事件代码如下:

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Bitmap bitmap = new Bitmap("image.jpg");

Rectangle rectangle1 = new Rectangle(10, 80, 100, 60);

Rectangle rectangle2 = new Rectangle(130, 30, 283, 198);

Rectangle rectangle3 = new Rectangle(435, 20, 300, 210);

graphics.DrawImage(bitmap, rectangle1);

graphics.DrawImage(bitmap, rectangle2);

graphics.DrawImage(bitmap, rectangle3);

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _6_19

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Graphics graphics = this.CreateGraphics();

Bitmap bitmap = new Bitmap("image.jpg");

Rectangle rectangle1 = new Rectangle(10, 80, 100, 60);

Rectangle rectangle2 = new Rectangle(130, 30, 283, 198);

Rectangle rectangle3 = new Rectangle(435, 20, 300, 210);

graphics.DrawImage(bitmap, rectangle1);

graphics.DrawImage(bitmap, rectangle2);

graphics.DrawImage(bitmap, rectangle3);

}

}

}

★ ★★★★Form1.Designer.cs窗体设计文件完整程序代码★★★★★

namespace _6_19

{

partial class Form1

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(24, 12);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 0;

this.button1.Text = "缩放图像";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(746, 249);

this.Controls.Add(this.button1);

this.MaximizeBox = false;

this.Name = "Form1";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button1;

}

}

★ ★★★★Program.cs主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _6_19

{

static class Program

{

///


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.