绘制实心矩形

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的更多相关文章

  1. 超全面的.NET GDI+图形图像编程教程

    本篇主题内容是.NET GDI+图形图像编程系列的教程,不要被这个滚动条吓到,为了查找方便,我没有分开写,上面加了目录了,而且很多都是源码和图片~ (*^_^*) 本人也为了学习深刻,另一方面也是为了 ...

  2. (转载)GDI+双缓冲

    双缓冲在GDI+里可以有效的提高描画效率.改善显示的质量. 下面的代码是一个最简单的双缓冲的模板.可以根据需要,做简单的修改即可. Bitmap CacheImage( [Width], [Heigh ...

  3. (转载)解决GDI闪烁

    一般的windows 复杂的界面需要使用多层窗口而且要用贴图来美化,所以不可避免在窗口移动或者改变大小的时候出现闪烁. 先来谈谈闪烁产生的原因 原因一:如果熟悉显卡原理的话,调用GDI函数向屏幕输出的 ...

  4. 通过GDI+绘制 验证码

    只为了记录下自己的学习历程,方便日后查看 现在开始言归正传,以下为其完整代码附上 using System; using System.Collections.Generic; using Syste ...

  5. 【VC++技术杂谈007】使用GDI+进行图片格式转换

    本文主要介绍如何使用GDI+对图片进行格式转换,可以转换的图片格式为bmp.jpg.png. 1.加载GDI+库 GDI+是GDI图形库的一个增强版本,提供了一系列Visual C++ API.为了使 ...

  6. C# GDI绘制矩形框,鼠标左键拖动可移动矩形框,滚轮放大缩小矩形框

    最近工作需要,要做一个矩形框,并且 用鼠标左键拖动矩形框移动其位置.网上查了一些感觉他们做的挺复杂的.我自己研究一天,做了一个比较简单的,发表出来供大家参考一下.如觉得简单,可路过,谢谢.哈哈. 先大 ...

  7. 【Windows编程】系列第五篇:GDI图形绘制

    上两篇我们学习了文本字符输出以及Unicode编写程序,知道如何用常见Win32输出文本字符串,这一篇我们来学习Windows编程中另一个非常重要的部分GDI图形绘图.Windows的GDI函数包含数 ...

  8. GDI+ 笔记

    1.GDI+模板 #include<windows.h> #include<GdiPlus.h> #include <time.h> #include <ma ...

  9. C# GDI+发生一般性错误(A generic error occurred in GDI+))

    解决思路: 1. 因为 .net GDI+ 是对底层 的封装. 所以可以尝试用 Marshal.GetLastWin32Error();函数获得底层错误代码. try{ image.Save(file ...

  10. GDI与GDI+ 贴图性能对比

    在做绘图相关工作,由于对显示绘制结果实时性有要求,筛选了GDI , 与GDI+ 贴图性能. 这里假设在内存中已绘制完成一张图片,现需求显示在控件上,同时,总是更新全部区域. GDI+ 实现 priva ...

随机推荐

  1. iptables的启动和关闭【转载】

    原文网址:http://os.51cto.com/art/201103/249049.htm iptables的启动和关闭: 1.启动和关闭iptables 下面将正式使用iptables来创建防火墙 ...

  2. spark分区

    spark默认的partition的分区数是和本机CPU的核数保持一致: bucket的数量和reduce的数量一致:buket的概念是map会将计算获得数据放到各个buket中,每个bucket和一 ...

  3. PHP判断键值数组是否存在,使用empty或isset或array_key_exists(转)

    一个例子 猜猜看,下面的例子会输出什么? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <?php $a = array('a'=>1, 'b'=>0, 'c'= ...

  4. spring mybatis 多个数据源配置

    mybatis生成器:http://blog.csdn.net/tolcf/article/details/50835165 通过命令生成:java -jar mybatis-generator-co ...

  5. Azure SLB + httpd + ILB + HAProxy + Atlas + MySQL

    为了测试一个环境,需要在Azure上搭建高可用的LAMP架构.但要求MySQL的中间件Atlas采用主备的模式.在数据中心一般采用Keepalive+VIP的模式,通过浮动地址对外提供服务. 但在云环 ...

  6. POJ3292(素数筛选)

    Semi-prime H-numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8706   Accepted: 3 ...

  7. Boost.Asio基本原理(CSDN也有Markdown了,好开森)

    Boost.Asio基本原理 这一章涵盖了使用Boost.Asio时必须知道的一些事情.我们也将深入研究比同步编程更复杂.更有乐趣的异步编程. 网络API 这一部分包含了当使用Boost.Asio编写 ...

  8. Python 正则表达式取值

    import re class Retest: def __init__(self,string,path): self.string = string self.path = path def re ...

  9. Mongodb 副本集的节点详细操作

    副本集操作 官方文档:https://docs.mongodb.com/v3.2/reference/method/js-replication/ 1 rs.add(){ _id: <int&g ...

  10. urllib2模块中文翻译与学习 - Python 2.7.8官方文档

    总结 目的 打开指定网址 要求 了解需要处理的网站的操作流程 数据包的构造与提交 对可能的响应处理选择合适的处理器(模块内的各种 *Handler()) 核心 urllib.urlencode(que ...