1 Star 3 Fork 0

CIMYong/ImageViewer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
KP-DrawEngine.cs 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
CIMYong 提交于 2020-03-11 10:03 . 初始化
using System.Drawing;
using System;
namespace KaiwaProjects
{
class KP_DrawEngine
{
/// <summary>
/// Original class to implement Double Buffering by
/// NT Almond
/// 24 July 2003
///
/// Extended and adjusted by
/// Jordy "Kaiwa" Ruiter
/// </summary>
///
private Graphics graphics;
private Bitmap memoryBitmap;
private int width;
private int height;
public void Dispose()
{
if (graphics != null)
{
graphics.Dispose();
}
if (memoryBitmap != null)
{
memoryBitmap.Dispose();
}
}
public KP_DrawEngine()
{
try
{
width = 0;
height = 0;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("ImageViewer error: " + ex.ToString());
}
}
public bool CreateDoubleBuffer(Graphics g, int width, int height, int previewWidth, int previewHeight)
{
try
{
KaiwaProjects.KP_DrawObject.UpdatePanelsize(width, height);
KaiwaProjects.KP_DrawObject.UpdatePreviewPanelsize(previewWidth, previewHeight);
if (memoryBitmap != null)
{
memoryBitmap.Dispose();
memoryBitmap = null;
}
if (graphics != null)
{
graphics.Dispose();
graphics = null;
}
if (width == 0 || height == 0)
return false;
this.width = width;
this.height = height;
memoryBitmap = new Bitmap(width, height);
graphics = Graphics.FromImage(memoryBitmap);
return true;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("ImageViewer error: " + ex.ToString());
return false;
}
}
public void Render(Graphics g)
{
try
{
if (memoryBitmap != null)
{
g.DrawImage(memoryBitmap, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("ImageViewer error: " + ex.ToString());
}
}
public bool CanDoubleBuffer()
{
try
{
return graphics != null;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("ImageViewer error: " + ex.ToString());
return false;
}
}
public Graphics g
{
get
{
return graphics;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/yongxin1/ImageViewer.git
[email protected]:yongxin1/ImageViewer.git
yongxin1
ImageViewer
ImageViewer
master

搜索帮助