C# GDI
绘制实心矩形
using (Graphics gp = Graphics.FromImage(bmBlank))
{
//...
int y = (int)currentPoint.Y - ;
Rectangle rec = new Rectangle(, y, , );//画一个白块,即起到擦拭的效果
gp.FillRectangle(Brushes.White, rec);
Brushes颜色参考
绘图基本方法
string backImage = GetMaterialPath(param, this.reportType) + "image_blank_1.png";
using (Image im = Image.FromFile(backImage))
{
using (Bitmap bmBlank = new Bitmap(, , Graphics.FromImage(im)))
{
using (Graphics gp = Graphics.FromImage(bmBlank))
{
gp.DrawImage(im, new Point(, ));
int width = (int)GetWidth_1(teamScore);
Rectangle rec = new Rectangle((int)baseX, (int)baseY, width, );
gp.FillRectangle(Brushes.Gold, rec);
}
ImageOperation.SaveImage(bmBlank, saveImgFilePath, );
}
}
//自定义工具类ImageOperation
public static void SaveImage(Bitmap myBitmap,string fileName, int quality)
{ System.Drawing.Imaging.EncoderParameters myEncoderParameters =
new System.Drawing.Imaging.EncoderParameters(); System.Drawing.Imaging.EncoderParameter myEncoderParameter =
new System.Drawing.Imaging.EncoderParameter(
System.Drawing.Imaging.Encoder.Quality, quality); myEncoderParameters.Param[] = myEncoderParameter; System.Drawing.Imaging.ImageCodecInfo myImageCodecInfo;
myImageCodecInfo = GetEncoderInfo("image/jpeg"); string ext = myImageCodecInfo.FilenameExtension.Split(';')[];
ext = System.IO.Path.GetExtension(ext).ToLower(); string saveName = System.IO.Path.ChangeExtension(fileName, ext); //保存
myBitmap.Save(saveName, myImageCodecInfo, myEncoderParameters);
}
using (FileStream fs = new FileStream(saveImgFilePath, FileMode.Create))
{
ImageCodecInfo imageCodeInfo = ImageOperation.GetEncoderInfo("image/jpeg");
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters();
myEncoderParameters.Param[] = new EncoderParameter(myEncoder, 99L);
bmBlank.Save(fs, imageCodeInfo, myEncoderParameters);
}
原生自定义背景色
Bitmap bmBlank = new Bitmap(width, height);
using (Graphics gp = Graphics.FromImage(bmBlank))
{
//清空画布并以白色背景色填充
gp.Clear(Color.White);
for (int i = ; i < imagePaths.Length; i++)
{
//加载一个图片
string imagePath = imagePaths[i];
//封装成Bitmap
Bitmap bm = new Bitmap(Image.FromFile(imagePath));
//切割此Bitmap为了等比例缩放
Bitmap newbm = ImageOperation.Cut(bm, , , , );
//查找所绘制每张图的新坐标
int x = xValue[i];
int y = yValue[i];
gp.DrawImage(newbm, x, y, , );
bm.Dispose();
}
gp.Dispose();
//保存为图片...
}
C# GDI的更多相关文章
- 超全面的.NET GDI+图形图像编程教程
本篇主题内容是.NET GDI+图形图像编程系列的教程,不要被这个滚动条吓到,为了查找方便,我没有分开写,上面加了目录了,而且很多都是源码和图片~ (*^_^*) 本人也为了学习深刻,另一方面也是为了 ...
- (转载)GDI+双缓冲
双缓冲在GDI+里可以有效的提高描画效率.改善显示的质量. 下面的代码是一个最简单的双缓冲的模板.可以根据需要,做简单的修改即可. Bitmap CacheImage( [Width], [Heigh ...
- (转载)解决GDI闪烁
一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化,所以不可避免在窗口移动或者改变大小的时候出现闪烁. 先来谈谈闪烁产生的原因 原因一:如果熟悉显卡原理的话,调用GDI函数向屏幕输出的 ...
- 通过GDI+绘制 验证码
只为了记录下自己的学习历程,方便日后查看 现在开始言归正传,以下为其完整代码附上 using System; using System.Collections.Generic; using Syste ...
- 【VC++技术杂谈007】使用GDI+进行图片格式转换
本文主要介绍如何使用GDI+对图片进行格式转换,可以转换的图片格式为bmp.jpg.png. 1.加载GDI+库 GDI+是GDI图形库的一个增强版本,提供了一系列Visual C++ API.为了使 ...
- C# GDI绘制矩形框,鼠标左键拖动可移动矩形框,滚轮放大缩小矩形框
最近工作需要,要做一个矩形框,并且 用鼠标左键拖动矩形框移动其位置.网上查了一些感觉他们做的挺复杂的.我自己研究一天,做了一个比较简单的,发表出来供大家参考一下.如觉得简单,可路过,谢谢.哈哈. 先大 ...
- 【Windows编程】系列第五篇:GDI图形绘制
上两篇我们学习了文本字符输出以及Unicode编写程序,知道如何用常见Win32输出文本字符串,这一篇我们来学习Windows编程中另一个非常重要的部分GDI图形绘图.Windows的GDI函数包含数 ...
- GDI+ 笔记
1.GDI+模板 #include<windows.h> #include<GdiPlus.h> #include <time.h> #include <ma ...
- C# GDI+发生一般性错误(A generic error occurred in GDI+))
解决思路: 1. 因为 .net GDI+ 是对底层 的封装. 所以可以尝试用 Marshal.GetLastWin32Error();函数获得底层错误代码. try{ image.Save(file ...
- GDI与GDI+ 贴图性能对比
在做绘图相关工作,由于对显示绘制结果实时性有要求,筛选了GDI , 与GDI+ 贴图性能. 这里假设在内存中已绘制完成一张图片,现需求显示在控件上,同时,总是更新全部区域. GDI+ 实现 priva ...
随机推荐
- python之 前端HTML/CSS基础知识学习笔记
1. 文件结构: HTML文件的固定结构: <html> <head>...</head> <body>...</body> </ht ...
- c语言-树的基础知识
第一.树的定义: 1.有且只有一个称为根的节点 2.有若干个互不相交的子树,这些子树本身也是一颗树 第二.专业术语: 树的深度:从根节点到最低层,节点的层数 ,称之为树的深度. 根节点是第一 ...
- vue中父子组件传递信息实现
为了能够在父子组件中实现双向控制,需要以下的步骤: 第一步:子组件中挖坑 (1)在需要父组件填充具体内容的地方挖坑,方式为 <slot name="message">& ...
- Howto Reboot or halt Linux system in emergency (ZT)
http://www.cyberciti.biz/tips/reboot-or-halt-linux-system-in-emergency.html Linux kernel includes ma ...
- Microsoft Office Visio 2010如何创建UML 用例图
转自:https://blog.csdn.net/mmoooodd/article/details/10513059 1..在Microsoft Office2010中打开Microsoft Visi ...
- Android CTS(frome google)
Compatibility Test Suite How does the CTS work? The Compatibility Test Suite (CTS) is a free, commer ...
- JS中,日期对象(获取当前现在的年份,星期,时间)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- App.CSharp.Grid的ICells接口
using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Wi ...
- Javascript面向对象(二):构造函数的继承
这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有一个" ...
- MySQL中的多表插入更新与MS-SQL的对比
MySQL多表插入: INSERT INTO tdb_goods_cates (cate_name) SELECT goods_cate FROM tdb_goods GROUP BY goods_c ...