[高手救急]关于DirectDraw,这段代码就是运行不过

Tenner 2005-08-26 10:26:00
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX.DirectDraw;

namespace DirectDrawTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(432, 338);
this.Name = "Form1";
this.Text = "Form1";
this.Resize += new System.EventHandler(this.Form1_Resize);
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

}
#endregion

// DirectDraw 设备
private Device dev = new Device(CreateFlags.Default);

// 两个表面
private SurfaceDescription sdPrimary = null;
private SurfaceDescription sdSecondary = null;
private Surface surPrimary = null;
private Surface surSecondary = null;

// 一个后台表面
private SurfaceDescription sdImage = null;
private Surface surImage = null;

// 表面的矩形区域
private Rectangle rPrimary, rSecondary, rImage;

// Image
private Bitmap bmp;

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void InitDDraw()
{
// Set Cooperative Level
dev.SetCooperativeLevel(this, CooperativeLevelFlags.Normal);

// Primary Surface
sdPrimary = new SurfaceDescription();
sdPrimary.SurfaceCaps.PrimarySurface = true;
sdPrimary.SurfaceCaps.Flip = true;
sdPrimary.BackBufferCount = 1;

// !!!! 运行到这句就出错,提示是“应用程序错误”
surPrimary = new Surface(sdPrimary, dev);

// Secondary Surface
sdSecondary = new SurfaceDescription();
sdSecondary.SurfaceCaps.BackBuffer = true;

surSecondary = surPrimary.GetAttachedSurface(sdSecondary.SurfaceCaps);
surSecondary.ForeColor = Color.White;
surSecondary.FontTransparency = true;

// Image
bmp = (Bitmap)Image.FromFile(@"E:\image.jpg");
}

private void LoadSurface()
{
sdImage = new SurfaceDescription();
sdImage.SurfaceCaps.OffScreenPlain = true;
sdImage.Width = surSecondary.SurfaceDescription.Width;
sdImage.Height = surSecondary.SurfaceDescription.Height;

surImage = new Surface(bmp, sdImage, dev);

rPrimary.Width = surPrimary.SurfaceDescription.Width;
rPrimary.Height = surPrimary.SurfaceDescription.Height;
rSecondary.Width = surSecondary.SurfaceDescription.Width;
rSecondary.Height = surSecondary.SurfaceDescription.Height;
rImage.Width = surImage.SurfaceDescription.Width;
rImage.Height = surImage.SurfaceDescription.Height;
}

private void draw()
{
if (surSecondary == null)
{
return;
}
surSecondary.DrawFast(0, 0, surImage, rImage, DrawFastFlags.Wait);
surPrimary.Flip(null, FlipFlags.NoVSync);
}

private void Form1_Load(object sender, System.EventArgs e)
{
InitDDraw();
LoadSurface();
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
draw();
}

private void Form1_Resize(object sender, System.EventArgs e)
{
draw();
}
}
}

为什么?
...全文
98 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tenner 2005-08-26
  • 打赏
  • 举报
回复
顶,高手帮忙啊
spz1755 2005-08-26
  • 打赏
  • 举报
回复
帮你顶
Tenner 2005-08-26
  • 打赏
  • 举报
回复
完全没人理....郁闷
一、项目简介 本项目(HF24075 SDFeatureRivertraining)是一套以多路 PWM 多彩 LED 灯光控制为核心的固件方案,基于 PADAUK PMS 系列单片机。方案对蓝、青、粉等多色 LED 进行独立 PWM 调光,实现呼吸、渐变、流水等细腻灯光效果,并支持按键切换与传感器交互。其 PWM 调光结构清晰,是学习单片机 PWM、色彩混合与灯光算法的理想范例。 核心应用场景: 1. 氛围灯 / 流水灯产品开发 2. PWM 调光与色彩混合学习 3. 电子类课程设计 / 毕业设计 4. 灯光艺术与 DIY 项目 适配使用场景:学习练手、毕业设计、课程设计、创业售卖、实操实训,突出实用性与可落地性。 二、硬件核心配置 · 主控芯片:PADAUK(应广科技)PMS 系列 8 位 OTP 单片机 · 外接外设: - 多色 LED 灯组(蓝 / 青 / 粉等多路独立 PWM) - 轻触按键(模式切换) - 传感器(交互触发) · 操控设备: - 机身实体按键操控 三、核心功能介绍 1. 多路独立 PWM 调光:蓝、青、粉等 LED 各自独立占空比控制,实现精准亮度; 2. 呼吸 / 渐变 / 流水效果:通过 PWM 变化曲线营造丰富灯光律动; 3. 按键切换模式:轻触在多种灯效间循环切换; 4. 传感器交互:外部传感信号触发或联动灯光变化; 5. 低功耗设计:闲置进入低功耗,按需唤醒。 6. 参数可配:亮灭周期、渐变速度等可调,便于定制。 四、项目优势与亮点 · 灯光细腻:多路独立 PWM,效果远胜简单开关灯。 · 算法清晰:呼吸 / 渐变实现简洁,易于理解与移植。 · 扩展性强:可轻松增加颜色与模式,适配各类灯饰。 ·

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧