基本信息
源码名称:C# 文本图像旋转示例源码(TransformRotate)
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2019-02-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TransformRotate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

         private void DoIt()
        {
            int trX = 0, trY = 0, R = 0, DSX = 0, DSY = 0;

            if (!int.TryParse(tbTrX.Text, out trX)) trX = 0;
            if (!int.TryParse(tbTrY.Text, out trY)) trY = 0;
            if (!int.TryParse(tbR.Text, out R)) R = 0;
            if (!int.TryParse(tbDSX.Text, out DSX)) DSX = 0;
            if (!int.TryParse(tbDSY.Text, out DSY)) DSX = 0;

            System.Drawing.Font drawFont = new System.Drawing.Font("Microsoft Sans Serif", (float)8.25);
            StringFormat SF=new StringFormat();

            if (rbAN.Checked) SF.Alignment = StringAlignment.Near;
            else if (rbAC.Checked) SF.Alignment = StringAlignment.Center;
            else if (rbAF.Checked) SF.Alignment = StringAlignment.Far;

            if (rbLAN.Checked) SF.LineAlignment = StringAlignment.Near;
            else if (rbLAC.Checked) SF.LineAlignment = StringAlignment.Center;
            else if (rbLAF.Checked) SF.LineAlignment = StringAlignment.Far;

            // Our picturebox is an empty container, so we must create the bitmap to go in it.
            Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            //Now make a GDI  graphics connection to the bitmap
            Graphics gr1 = Graphics.FromImage(bmp1);

            //We want our text to look good, so we'll tell GDI  to apply AntiAliasing to anything we add
            gr1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            //Now we're ready to perform our first function - TranslateTransform
            //We're not actually moving anything graphical here, we're just telling GDI 
            //that we want to move the origin of the graphics object for subsequent rendering
            gr1.TranslateTransform(trX, trY);

            //Next comes the RotateTransform
            //Again we're not actually moving anything graphical, we're just telling GDI 
            //that anything we draw from now on is to be rotated.
            gr1.RotateTransform(R);

            //Now add the text.
            gr1.DrawString("Some text", drawFont, Brushes.Black, DSX, DSY,SF);
//            gr1.DrawLine(Pens.Black,DSX,DSY 12,DSX 50,DSY 12 );

            //Finally, put the bitmap (which has been updated via GDI ) into the picturebox.
            pictureBox1.Image = bmp1;

            Bitmap bmp2 = new Bitmap(pictureBox2.Width, pictureBox2.Height);
            Graphics gr2 = Graphics.FromImage(bmp2);
            gr2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            gr2.TranslateTransform(trX, trY);
            gr2.RotateTransform(R);
            gr2.DrawString("Some text", drawFont, Brushes.Black, DSX, DSY, SF);
//            gr2.DrawLine(Pens.Black, DSX, DSY   12, DSX   50, DSY   12);
            pictureBox2.Image = bmp2;

        }

         private void DoIt(object sender, EventArgs e)
         {
             DoIt();
         }


        private void Form1_Load(object sender, EventArgs e)
        {
            tbTrX.Text = "0";
            tbTrY.Text = "0";
            tbR.Text = "0";
            tbDSX.Text = "0";
            tbDSY.Text = "0";
            rbAN.Checked = true;
            rbLAN.Checked = true;
        }
    }
}