private void Form8_Paint(object sender, PaintEventArgs e)
{
// 创建一个全部由线条组成的路径
PointF[] points = new PointF[]
{
new PointF(20.0f, 60.0f),
new PointF(30.0f, 90.0f),
new PointF(15.0f, 110.0f),
new PointF(15.0f, 145.0f),
new PointF(55.0f, 145.0f),
new PointF(55.0f, 110.0f),
new PointF(40.0f, 90.0f),
new PointF(50.0f, 60.0f)
};
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
path.CloseFigure();
// 绘制扭曲前的路径
Pen bluePen = new Pen(Color.Blue, 3);
e.Graphics.DrawPath(bluePen, path);
// 定义放置路径的源矩形
RectangleF srcRect = new RectangleF(10.0f, 50.0f, 50.0f, 100.0f);
//定义矩形映射的目标点
PointF[] destPts = new PointF[]
{
new PointF(200.0f, 10.0f),
new PointF(250.0f, 10.0f),
new PointF(100.0f, 150.0f),
new PointF(300.0f, 150.0f)
};
//扭曲矩形
path.Warp(destPts, srcRect);
// 绘制扭曲后的路径
e.Graphics.DrawPath(bluePen, path);
我想通过矩阵转换可以实现拉伸,扭曲等各种效果,可怜我当年没好好上学
下面的例子改自深入managed directx3d,只是一个示范
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Drawing;
using System.Threading;
namespace WrapRectImage
{
public class Form1 : Form
{
CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[6];
verts[0] = new CustomVertex.PositionTextured(-1f, 1.0f, 0.0f, 0.0f, 0.0f);
verts[1] = new CustomVertex.PositionTextured(-1f, -1.0f, 0.0f, 0.0f, 1.0f);
verts[2] = new CustomVertex.PositionTextured(1f, 1.0f, 0.0f, 1.0f, 0.0f);
verts[3] = new CustomVertex.PositionTextured(-1f, -1.0f, 0.0f, 0.0f, 1.0f);
verts[4] = new CustomVertex.PositionTextured(1f, -1.0f, 0.0f, 1.0f, 1.0f);
verts[5] = new CustomVertex.PositionTextured(1f, 1.0f, 0.0f, 1.0f, 0.0f);
buffer.SetData(verts, 0, LockFlags.None);
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
#region Windows Form Designer generated code
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using (Form1 frm = new Form1())
{
// Show our form and initialize our graphics engine
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
#endregion
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 100.0f);
//调整相机的位置,可以取各种角度变形
//当然,计算好了位置和角度再来拍才是你想要的结果
Random ra = new Random();
float x = ra.Next(10) - 5;
float y = ra.Next(10) - 5;
float z = 3;
Vector3 cameraPosition = new Vector3(x, y, z);
device.Transform.View = Matrix.LookAtLH(cameraPosition, new Vector3(), new Vector3(0, 1, 0));
device.RenderState.Lighting = false;