c#实现图片的平移和旋转示例代码

前言

本文主要给大家分享了关于利用c#实现图片的平移和旋转的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧

方法如下

1新建文件夹,添加一个图片

2 添加控件 两个button控件 一个image控件 一个Canvas控件

3 代码实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication16
{
 /// <summary>
 /// MainWindow.xaml 的交互逻辑
 /// </summary>
 public partial class MainWindow : Window
 {
  public MainWindow()
  {
   InitializeComponent();
  }
  private void button_Click(object sender, RoutedEventArgs e)
  {
   DoubleAnimation da = new DoubleAnimation();
   da.From = 0;
   da.To = -100;
   Storyboard board = new Storyboard();
   Storyboard .SetTarget(da,image);
   Storyboard.SetTargetProperty(da,new PropertyPath(Canvas.LeftProperty));
   board.Children.Add(da);
   board.Begin();
  }
  private void xuanzhuan()
  {
   RotateTransform totate = new RotateTransform();
   image.RenderTransform = totate;
   image.RenderTransformOrigin = new Point(0.5, 0.5);
   DoubleAnimation da = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromMilliseconds(500)));
   Storyboard board = new Storyboard();
   Storyboard.SetTarget(da, image);
   Storyboard.SetTargetProperty(da,new PropertyPath("RenderTransform.Angle"));
   da.RepeatBehavior = RepeatBehavior.Forever;
   da.Completed += Da_Completed;
   board.Children.Add(da);
   board.Begin();

  }
  private void Da_Completed(object sender, EventArgs e)
  {

  }
  private void button1_Click(object sender, RoutedEventArgs e)
  {
   xuanzhuan();
  }
 }
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。

(0)

相关推荐

  • C#控制图像旋转和翻转的方法

    本文实例讲述了C#控制图像旋转和翻转的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication2 { public par

  • C#中图片旋转和翻转(RotateFlipType)用法分析

    本文实例分析了C#中图片旋转和翻转(RotateFlipType)用法.分享给大家供大家参考.具体如下: 首次接触Image.RotateFlip时可能会对它的旋转方式搞糊涂,其中旋转时有许多参数如: 1.Rotate90FlipX 2.Rotate90FliY 3.Rotate90FlipXY 4.Rotate90FlipNone 以上面四个为例: 1是指定后接水平翻转的90度顺时针旋转, 2是指定后接垂直翻转的90度顺时针旋转, 3是指定后接水平翻转和垂直翻转的90度顺时针旋转, 4是指定不

  • C# 使用 GDI+ 实现添加中心旋转(任意角度)的文字

    前言 这篇文章是 GDI+ 总结系列的第三篇,如果对 GDI+ 的基础使用不熟悉的朋友可以先看第一篇文章<C# 使用 GDI+ 画图>. 需求 需求是要实现给图片添加任意角度旋转的文字,文字的旋转中心要是在文字区域中央,就像 CSS 的 rotate 函数一样的效果.如下: 分析&思路 Graphics 类有个 RotateTransform 方法,可以传入任意角度的值来旋转画板.但是这个方法的旋转中心是画板的左上角,所以直接单单用这个方法不能满足我们的需求.此外, Graphics

  • C#图像处理之图像平移的方法

    本文实例讲述了C#图像处理之图像平移的方法.分享给大家供大家参考.具体如下: //定义图像平移函数 private static Bitmap offsetp(Bitmap a,int s,int v) { System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle (0,0,a.Width ,a.Height) ,System .Drawing .Imaging .ImageLockMode .ReadWrite ,

  • C# 实现的图片盖章功能,支持拖拽、旋转、放缩、保存

    实现图片盖章功能,在图片上点击,增加"图章"小图片,可以拖拽"图章"到任意位置,也可以点击图章右下角园框,令图片跟着鼠标旋转和放缩. 操作方法:1.点击增加"图章"2.选中移动图标3.点中右下角放缩旋转图章. 效果图: 实现代码如下: 1.  窗口Xaml代码 复制代码 代码如下: <Window x:Class="Lenovo.YogaPaster.ImageEditWindow"    xmlns="htt

  • 利用C#代码实现图片旋转360度

    using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Text; namespace 图片旋转程序 { public class ImageHelper { /// <summary> /// 以逆时针为方向对图像进行旋转 /// </summary> /// <param name="

  • C#实现计算一个点围绕另一个点旋转指定弧度后坐标值的方法

    本文实例讲述了C#实现计算一个点围绕另一个点旋转指定弧度后坐标值的方法.分享给大家供大家参考.具体如下: 1.示例图 P(x1,y1)以点A(a,b)为圆心,旋转弧度为θ,求旋转后点Q(x2,y2)的坐标 2.实现方法 先将坐标平移,计算点(x1-a,y1-b)围绕原点旋转后的坐标,再将坐标轴平移到原状态 /// <summary> /// 结构:表示一个点 /// </summary> struct Point { //横.纵坐标 public double x, y; //构造

  • C#利用GDI+绘制旋转文字等效果实例

    本文实例讲述了C#利用GDI+绘制旋转文字等效果的方法,是非常实用的技巧.分享给大家供大家参考之用.具体如下: C#中利用GDI+绘制旋转文本的文字,网上有很多资料,基本都使用矩阵旋转的方式实现.但基本都只提及按点旋转,若要实现在矩形范围内旋转文本,资料较少.经过琢磨,可以将矩形内旋转转化为按点旋转,不过需要经过不少的计算过程.利用下面的类可以实现该功能. 具体实现代码如下: using System; using System.Collections.Generic; using System

  • C#实现字体旋转的方法

    本文实例讲述了C#实现字体旋转的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace adv

  • c#实现图片的平移和旋转示例代码

    前言 本文主要给大家分享了关于利用c#实现图片的平移和旋转的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 方法如下 1新建文件夹,添加一个图片 2 添加控件 两个button控件 一个image控件 一个Canvas控件 3 代码实现 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; us

  • Android绘制平移动画的示例代码

    目录 1.具体操作步骤 2.具体实施 创建ImageView 创建ObjectAnimator对象 3.具体实例 activity_main.xml MainActivity.java 1.具体操作步骤 创建ImageView对象 创建ObjectAnimator对象 通过ofFloat方法实现平移 2.具体实施 创建ImageView <ImageView android:id="@+id/car" android:layout_width="wrap_content

  • 基于Vue2x的图片预览插件的示例代码

    本文介绍了基于Vue2x的图片预览插件的示例代码,分享给大家,具体如下: 先来看下Demo LiveDemo 关于开发Vue插件的几种方式 (具体请移步官网)Vue官网 MyPlugin.install = function (Vue, options) { // 1. 添加全局方法或属性 Vue.myGlobalMethod = function () { // 逻辑... } // 2. 添加全局资源 Vue.directive('my-directive', { bind (el, bin

  • weui上传多图片,压缩,base64编码的示例代码

    记录一下在做一个报修功能的心路历程,需求功能很简单,一个表单提交,表单包含简单的文字字段以及图片 因为使用的是weui框架,前面的话去找weui的表单和图片上传组件,说实话,weui的组件写的还不错,作为一个不太懂前端的渣渣可以拿来开箱即用 主要是不用调那么多的样式问题,直接上代码: <div class="weui-cell"> <div class="weui-cell__bd"> <div class="weui-upl

  • Java实现图片转换PDF文件的示例代码

    最近因为一些事情,需要将一张简单的图片转换为PDF的文件格式,在网上找了一些工具,但是这些工具不是需要注册账号,就是需要下载软件. 而对于只是转换一张图片的情况下,这些操作显然是非常繁琐的,所以作者就直接使用Java写了一个图片转换PDF的系统,现在将该系统分享在这里. 引入依赖 <!--该项目以SpringBoot为基础搭建--> <parent> <groupId>org.springframework.boot</groupId> <artifa

  • asp.net core集成CKEditor实现图片上传功能的示例代码

    背景 本文为大家分享了asp.net core 如何集成CKEditor ,并实现图片上传功能的具体方法,供大家参考,具体内容如下. 准备工作 1.visual studio 2019 开发环境 2.net core 2.0 及以上版本 实现方法 1.新建asp.net core web项目 2.下载CKEditor 这里我们新建了一个系统自带的样本项目,去 CKEditor官网下载一个版本,解压后拷贝大wwwroot中 3.增加图片上传控制器 @using CompanyName.Projec

  • Golang实现图片上传功能的示例代码

    目录 1.前端代码 2.JS代码 3.后端代码 该代码为使用beego实现前后端图片上传.话不多说,直接上代码. 1.前端代码 html代码: <div class="col-5 f-l text text-r">背景图(必须):</div> <div class="img-box"> <label> <span class="copy-btn Hui-iconfont"></s

  • C#实现图片轮播功能的示例代码

    目录 实践过程 效果 代码 实践过程 效果 代码 public partial class Form1 : Form { public Form1() { InitializeComponent(); } public bool Pflag; int flag = 0; FileSystemInfo[] fsinfo; ArrayList al = new ArrayList(); int MM = 0; private void splitContainer2_Panel2_Paint(obj

  • Android 图片Bitmap的剪切的示例代码

    一.什么是Android中的Bitmap Bitmap是Android系统中的图像处理的最重要类之一.用它可以获取图像文件信息,进行图像剪切.旋转.缩放等操作,并可以指定格式保存图像文件. 二.Bitmap的剪切基本操作 复制代码 代码如下: public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter) 从原始位图剪切图像,这是一种高

  • JS实现单张或多张图片持续无缝滚动的示例代码

    背景: 想要实现图片持续滚动,既然使用js,就千万不要加css动画.过渡等相关样式,如果想要滚动的平滑一下,可以一像素一像素的感动,则很平滑,如果加了过渡动画,当图片重置为0时,会有往回倒的动画效果,跟预期不符. 原理: 图片滚动原理同图片轮播原理,同样也适用于文字滚动等一系列滚动,通过复制最后一张图片或最后一堆文字插入第一行,或复制第一张图片或一堆文字插入在结尾,来实现无缝拼接,前提:1.必须是没有设置过渡动画的,2.重置为0的时候与当前已经滚动到的高度对于图片的位置而言肉眼看上去没变化. 实

随机推荐