最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#使用游標(biāo)實現(xiàn)補間函數(shù)

 更新時間:2022年02月21日 16:22:39   作者:RunnerDNA  
這篇文章主要為大家詳細(xì)介紹了C#使用游標(biāo)實現(xiàn)補間函數(shù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

補間可以實現(xiàn)兩個圖形之間顏色、形狀、大小、位置等的線性變化。

例如A...AB...BC...C,其中A、B、C是三幅圖片,兩個A的寬分別是10cm和50cm,兩個A之間共5幀,那么使用補間操作后,A圖片的寬分別是10cm、20cm、30cm、40cm、50cm,B和C圖片的寬度計算同理。對于A...ABC...C或者A...ABBC...C這種情況,B不進行補間操作。

下面新建一個控制臺處理程序,添加圖片類ImageClass.cs。

public class ImageClass
{
? ? //寬
? ? public int Width { get; set; }
? ? //高
? ? public int Height { get; set; }
? ? //模擬判斷是否是同一張圖片
? ? public string Path { get; set; }
? ? public ImageClass(int _width,int _height,string _path)
? ? {
? ? ? ? Width = _width;
? ? ? ? Height = _height;
? ? ? ? Path = _path;
? ? }
}

新建圖片幀類ImgFrameClass.cs。

public class ImgFrameClass
{
? ? public ImageClass FramesImg { get; set; }
? ? public int Frames { get; set; }//圖片位于的幀數(shù)
?
? ? public ImgFrameClass(ImageClass _frameImg, int _frames)
? ? {
? ? ? ? FramesImg = _frameImg;
? ? ? ? Frames = _frames;
? ? }
}

新建補間算法類,需要引用Newtonsoft.Json。

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
?
namespace TweenDemo
{
? ? public class Utility
? ? {
? ? ? ? public static List<ImgFrameClass> SetTween(List<ImgFrameClass> _imgFrameList)
? ? ? ? {
? ? ? ? ? ? List<ImgFrameClass> imgFrameResultList = new List<ImgFrameClass>();
? ? ? ? ? ? List <ImgFrameClass> imgFrameList = DeepCopyWithSerialization(_imgFrameList);
? ? ? ? ? ? //定義兩個游標(biāo),初始化為相鄰游標(biāo)
? ? ? ? ? ? int b = 0, a = 1;
? ? ? ? ? ? int len = imgFrameList.Count;
? ? ? ? ? ? //存在相同元素的個數(shù)
? ? ? ? ? ? int count = 0;
? ? ? ? ? ? string samePath = string.Empty;
? ? ? ? ? ? while (a < len)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ImgFrameClass itemb = imgFrameList[b];
? ? ? ? ? ? ? ? ImgFrameClass itema = imgFrameList[a];
?
? ? ? ? ? ? ? ? while (b >= 0 && a < len && (imgFrameList[b].FramesImg.Path == imgFrameList[a].FramesImg.Path))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? samePath = imgFrameList[b].FramesImg.Path;
? ? ? ? ? ? ? ? ? ? while (a < len && (imgFrameList[a].FramesImg.Path == samePath))
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? a++;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? count = count + 2;
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? if (count != 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ImgFrameClass tweenStartItem = imgFrameList[b];
? ? ? ? ? ? ? ? ? ? ImgFrameClass tweenStopItem = imgFrameList[a - 1];
? ? ? ? ? ? ? ? ? ? //添加初始圖片
? ? ? ? ? ? ? ? ? ? imgFrameResultList.Add(tweenStartItem);
?
? ? ? ? ? ? ? ? ? ? ImageClass tweenStartImg = DeepCopyWithSerialization(tweenStartItem.FramesImg);
? ? ? ? ? ? ? ? ? ? ImageClass tweenStopImg = DeepCopyWithSerialization(tweenStopItem.FramesImg);
? ? ? ? ? ? ? ? ? ? double tweenFrame = tweenStopItem.Frames - tweenStartItem.Frames;
? ? ? ? ? ? ? ? ? ? double tweenImgW = (double)(tweenStopImg.Width - tweenStartImg.Width) / tweenFrame;
? ? ? ? ? ? ? ? ? ? double tweenImgH = (double)(tweenStopImg.Height - tweenStartImg.Height) / tweenFrame;
?
? ? ? ? ? ? ? ? ? ? int coutStart = tweenStartItem.Frames;
? ? ? ? ? ? ? ? ? ? int coutStop = tweenStopItem.Frames;
? ? ? ? ? ? ? ? ? ? //插入補間圖片
? ? ? ? ? ? ? ? ? ? for (int i = coutStart + 1; i < coutStop; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ImageClass tweenAddImg = new ImageClass((int)(tweenStartImg.Width + tweenImgW * (i - coutStart)), (int)(tweenStartImg.Height + tweenImgH * (i - coutStart)),samePath);
? ? ? ? ? ? ? ? ? ? ? ? imgFrameResultList.Add(new ImgFrameClass(tweenAddImg,i));
? ? ? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? ? ? //添加末尾圖片
? ? ? ? ? ? ? ? ? ? imgFrameResultList.Add(tweenStopItem);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? imgFrameResultList.Add(imgFrameList[b]);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //不滿足則正常移動游標(biāo),都向前移動一個,相同元素的個數(shù)置0
? ? ? ? ? ? ? ? b = a++;
? ? ? ? ? ? ? ? count = 0;
? ? ? ? ? ? }
? ? ? ? ? ? return imgFrameResultList;
? ? ? ? }
?
? ? ? ? public static T DeepCopyWithSerialization<T>(T obj)
? ? ? ? {
? ? ? ? ? ? string json = JsonConvert.SerializeObject(obj);
? ? ? ? ? ? T copy = JsonConvert.DeserializeObject<T>(json);
? ? ? ? ? ? return copy;
? ? ? ? }
? ? }
}

模擬生成AAAAABBBBCBB結(jié)構(gòu)的數(shù)據(jù),Main函數(shù)如下:

static void Main(string[] args)
{
? ? //模擬生成測試數(shù)據(jù)
? ? List<ImgFrameClass> imgFrameList = new List<ImgFrameClass>();
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(10, 10, "A"),1));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(50, 50, "A"), 5));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(10, 10, "B"), 6));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(80, 80, "B"), 9));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(10, 10, "C"), 10));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(10, 10, "B"), 11));
? ? imgFrameList.Add(new ImgFrameClass(new ImageClass(30, 30, "B"), 12));
?
? ? List<ImgFrameClass> imgFrameResultList = Utility.SetTween(imgFrameList);
? ? foreach (ImgFrameClass item in imgFrameResultList)
? ? {
? ? ? ? Console.WriteLine(string.Format("Img{0},width:{1},height:{2}", item.FramesImg.Path, item.FramesImg.Width, item.FramesImg.Height));
? ? }
? ? Console.ReadLine();
}

運行結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中Timer實現(xiàn)Tick使用精度的問題

    C#中Timer實現(xiàn)Tick使用精度的問題

    這篇文章主要介紹了C#中Timer實現(xiàn)Tick使用精度的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • UnityShader3實現(xiàn)2D描邊效果

    UnityShader3實現(xiàn)2D描邊效果

    這篇文章主要為大家詳細(xì)介紹了UnityShader3實現(xiàn)2D描邊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C#使用隨機數(shù)編寫班級點名器的示例代碼

    C#使用隨機數(shù)編寫班級點名器的示例代碼

    本文主要介紹了C#使用隨機數(shù)編寫班級點名器的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • C# DataSet的內(nèi)容寫成XML時如何格式化字段數(shù)據(jù)

    C# DataSet的內(nèi)容寫成XML時如何格式化字段數(shù)據(jù)

    許多讀者經(jīng)常詢問一個問題,那就是在將DataSet的內(nèi)容寫成XML時,如何格式化字段數(shù)據(jù)。最常見的需求,就是希望日期時間值與數(shù)值數(shù)據(jù)能夠以所需的格式呈現(xiàn)于XML中。
    2009-02-02
  • C#用表達式樹構(gòu)建動態(tài)查詢的方法

    C#用表達式樹構(gòu)建動態(tài)查詢的方法

    這篇文章主要介紹了C#用表達式樹構(gòu)建動態(tài)查詢的方法,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-12-12
  • c#中LINQ的基本用法(三)

    c#中LINQ的基本用法(三)

    這篇文章介紹了c#中LINQ的基本用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下的相關(guān)資料
    2022-04-04
  • 3種C# 加載Word的方法

    3種C# 加載Word的方法

    本次經(jīng)驗內(nèi)容分享通過C#程序來加載Word文檔的3種不同方法。分別是:加載本地Word文檔、以只讀模式加載Word文檔、從流加載Word 想具體了解的小伙伴請參考下文
    2021-09-09
  • C#自定義控件指示燈效果

    C#自定義控件指示燈效果

    在C#中實現(xiàn)一個指示燈控件,可以通過GDI+技術(shù)繪制,首先使用Pen對象繪制外環(huán),然后用SolidBrush對象填充內(nèi)圓,通過RectangleF定義繪制和填充的邊界,控件的屬性包括顏色、間隙、外環(huán)寬度等,本文給大家介紹C#自定義控件指示燈效果,感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • C#實現(xiàn)簡單學(xué)生信息管理系統(tǒng)

    C#實現(xiàn)簡單學(xué)生信息管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了C#實現(xiàn)簡單學(xué)生信息管理系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • C#中new的用法及與override的區(qū)別分析

    C#中new的用法及與override的區(qū)別分析

    這篇文章主要介紹了C#中new的用法,及與override的區(qū)別,需要的朋友可以參考下
    2017-05-05

最新評論

宣武区| 石嘴山市| 长海县| 绥德县| 新沂市| 东光县| 古田县| 涡阳县| 军事| 夏邑县| 高邑县| 金坛市| 措勤县| 华蓥市| 五莲县| 大同县| 封丘县| 桑日县| 扶绥县| 南部县| 大渡口区| 榆社县| 高平市| 南京市| 泰兴市| 鄂托克前旗| 白玉县| 吉水县| 祁东县| 文昌市| 佛坪县| 什邡市| 绥棱县| 双桥区| 习水县| 岳池县| 博白县| 兰州市| 奇台县| 武乡县| 乌海市|