学 生 实 验 报 告
实验课程名称 媒体技术
开课实验室
学 院
学 生 姓 名 学 号
开 课 时 间 20XX 20XX 学年第 学期
总 成 绩
教师签名
软件学院制
媒体技术实验报告
开课实验室: 2015 年 X月X 日
学院
年级专业班
姓名
成绩
课程
名称
媒体技术
实验项目
名 称
图变换动画
指导教师
教师评语
教师签名:
年 月 日
实验目
通两幅图变换实现动画效果
二实验原理
变形动画幅图动态变换幅相结构相似图中需两幅图体结构中标注应变换点变换程中应点进行形状结构变换
果考虑图形状结构变换简单实现幅图动态变换幅相图应变换点应素点确定实验该方式实现
样图需更复杂处理方式需定插值算法生成图变换产生额外素值终效果算法实验考虑该情形
变换结果先图文件方式存储然采两种方式实现动画展示:构造GIF动画软件变换程图连接成GIF动画行编制软件定速度开展示变换程图形成动画展示效果
理格式图文件均实现图变换动画里简化操作统BMP格式图文件
24位真彩色BMP图构造图变换动画图数阵列中应素点RGB值进行插值变换实现幅图中素点RGB值变换幅图中应素点RGB值
调色板BMP索引图生成图变换动画程稍稍复杂变换方式三种:(1)保持调色板变素点进行颜色变换素点变换应素点时根该素点索引值指调色板表项RGB应素点索引值指调色板表项RGB计算变换图RGB值然调色板中查找变换程图RGB值接表项应索引值作变换程图素索引值该方式改变原始调色板需变换程RGB值映射调色板中接表项(2)允许改变调色板素点进行颜色变换根变换图素点索引值找应调色板表项获取素点RGB值然24位真彩色BMP图变换相似方式通插值计算变换程图素点RGB值该方式变换程图中生成超256种RGB组合颜色果采索引图方式存储该图需行构造新调色板变换程图素点RGB值映射调色板中表项(3)保持调色板变素点进行索引值变换变换图素点索引值通插值计算变换程图索引值实现简单图变换
述三种图变换方式中第三种难实现滑图颜色变换效果较差第二种实现程较复杂需行生成新调色板第种行
三实验容
开两幅相BMP图分指定起始帧终止帧指定变换帧数实现图起始帧逐步变换终止帧副图动态变换幅图
四实验工具
VS2013
五实验步骤
果程序中实现图开显示变换动画显示利控制台程序读入图处理生成中间帧
果程序中实现图开显示变换动画显示里关键实验步骤分c++c#两版叙述提供实验方法阐述具体实现步骤:
1. C#版:
C#图操作已封装具体类Bitmap参阅资料熟悉Bitmap类中成员函数属性作动态效果利timer控件
1) MFC布局:
Time1Enabled 设置TrueInterval设置10000ms相10秒
Maincpp
using System
using SystemCollectionsGeneric
using SystemComponentModel
using SystemData
using SystemDrawing
using SystemLinq
using SystemText
using SystemThreadingTasks
using SystemWindowsForms
namespace animation
{
public partial class Form1 Form
{
public
Bitmap curBitmap
Bitmap souBitmap
Bitmap oriBitmap
public Form1()
{
InitializeComponent()
}
private void Form1_Load(object sender EventArgs e)
{
}
private void button1_Click(object sender EventArgs e)
{
OpenFileDialog fileDialog new OpenFileDialog()
timer1Stop()
fileDialogTitle 选择文件
fileDialogFilter bmp files (*bmp)|*bmp
fileDialogFilterIndex 1
fileDialogRestoreDirectory true
if (fileDialogShowDialog() DialogResultOK)
{
string fileName fileDialogFileName
string name fileNameSubstring(fileNameLastIndexOf(\\) + 1)
oriBitmap new Bitmap(fileName)
pictureBox1Image oriBitmap
curBitmap new Bitmap(fileName)
int bitmapHeight oriBitmapHeight
int bitmapWidth oriBitmapWidth
}
}
private void button2_Click(object sender EventArgs e)
{
OpenFileDialog fileDialog new OpenFileDialog()
timer1Stop()
fileDialogTitle 选择文件
fileDialogFilter bmp files(*bmp)|*bmp
fileDialogFilterIndex 1
fileDialogRestoreDirectory true
if (fileDialogShowDialog() DialogResultOK)
{
string fileName fileDialogFileName
oriBitmap new Bitmap(fileName)
souBitmap new Bitmap(fileName)
pictureBox2Image oriBitmap
}
}
private void timer1_Tick(object sender EventArgs e)
{
if (curBitmap null)
{
curBitmap (Bitmap)pictureBox1Image
Rectangle rect new Rectangle(0 0 curBitmapWidth curBitmapHeight)
Rectangle rect1 new Rectangle(0 0 souBitmapWidth souBitmapHeight)
SystemDrawingImagingBitmapData bmpData curBitmapLockBits(rect SystemDrawingImagingImageLockModeReadWrite curBitmapPixelFormat)
SystemDrawingImagingBitmapData bmpData1 souBitmapLockBits(rect1 SystemDrawingImagingImageLockModeReadWrite souBitmapPixelFormat)
首址
IntPtr ptr bmpDataScan0
IntPtr ptr1 bmpData1Scan0
24位BMP位图字节
int bytes curBitmapWidth * curBitmapHeight * 3
int bytes1 curBitmapWidth * curBitmapHeight * 3
定义位图数组
byte[] rgbValues new byte[bytes]
byte[] rgbValues1 new byte[bytes1]
复制锁定位图素值该数组
SystemRuntimeInteropServicesMarshalCopy(ptr rgbValues 0 bytes)
SystemRuntimeInteropServicesMarshalCopy(ptr1 rgbValues1 0 bytes1)
灰度化
double colorTemp 0
for (int i 0 i < rgbValuesLength i + 3)
{
Byte incre1 (byte)MathAbs(rgbValues1[i] rgbValues[i])
Byte incre2 (byte)MathAbs(rgbValues1[i + 1] rgbValues[i + 1])
Byte incre3 (byte)MathAbs(rgbValues1[i + 2] rgbValues[i + 2])
rgbValues[i] + incre1
rgbValues[i + 1] + incre2
rgbValues[i + 2] + incre3
}
数组复制回位图
SystemRuntimeInteropServicesMarshalCopy(rgbValues 0 ptr bytes)
SystemRuntimeInteropServicesMarshalCopy(rgbValues1 0 ptr1 bytes1)
解锁位图素
curBitmapUnlockBits(bmpData)
souBitmapUnlockBits(bmpData1)
pictureBox1Image curBitmap
}
}
private void button3_Click(object sender EventArgs e)
{
timer1Start()
}
}
}
六实验结果分析
通媒体实验熟悉C#编程简单界面操作
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档