再学 GDI+[91]: TGPImage(11) - 转灰度图像

本例效果图:

o_8743.gif

代码文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)CheckBox1: TCheckBox;procedure FormCreate(Sender: TObject);procedure FormPaint(Sender: TObject);procedure CheckBox1Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}uses GDIPOBJ, GDIPAPI;const{一般模式}ColorMatrix1: TColorMatrix = ((1.0, 0.0, 0.0, 0.0, 0.0),(0.0, 1.0, 0.0, 0.0, 0.0),(0.0, 0.0, 1.0, 0.0, 0.0),(0.0, 0.0, 0.0, 1.0, 0.0),(0.0, 0.0, 0.0, 0.0, 1.0));{灰度模式}ColorMatrix2: TColorMatrix = ((0.3,  0.3,  0.3,  0.0, 0.0),(0.59, 0.59, 0.59, 0.0, 0.0),(0.11, 0.11, 0.11, 0.0, 0.0),(0.0,  0.0,  0.0,  1.0, 0.0),(0.0,  0.0,  0.0,  0.0, 1.0));procedure TForm1.FormCreate(Sender: TObject);
beginCheckBox1.Caption := '转为灰度';
end;procedure TForm1.FormPaint(Sender: TObject);
varg: TGPGraphics;img: TGPImage;ImageAttributes: TGPImageAttributes;
beging := TGPGraphics.Create(Canvas.Handle);img := TGPImage.Create('c:\temp\test.png');ImageAttributes := TGPImageAttributes.Create;if CheckBox1.Checked thenImageAttributes.SetColorMatrix(ColorMatrix2)elseImageAttributes.SetColorMatrix(ColorMatrix1);g.DrawImage(img,MakeRect(4, 4, img.GetWidth, img.GetHeight),0,0,img.GetWidth,img.GetHeight,UnitPixel,ImageAttributes);ImageAttributes.Free;img.Free;g.Free;
end;procedure TForm1.CheckBox1Click(Sender: TObject);
beginRepaint;
end;end.
窗体文件:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 216ClientWidth = 269Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalsePosition = poDesktopCenterOnCreate = FormCreateOnPaint = FormPaintPixelsPerInch = 96TextHeight = 13object CheckBox1: TCheckBoxLeft = 183Top = 191Width = 79Height = 17Caption = 'CheckBox1'TabOrder = 0OnClick = CheckBox1Clickend
end

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/268884.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql下一个版本号_mysql下一个版本应该且实现并不复杂增加的常用功能

1、innodb的auto_increment应该在参考oracle的实现方式,定期持久化(mysql 8.0支持,mariadb 10.3支持序列);我们目前遇到个问题,出于性能考虑,我们每天会把当天处理完成的数据归到另外一张历史表,并清空&…

GUI阅读字号和触点面积设计 (可用性设计)

今天在博客园开启第一篇,附上我多年工作的研究总结以表诚意。 此文已收入UXPA大会文集,出版于四川大学出版社。 《GUI阅读字号和触点面积设计》 --可用性设计理论研究与实践案例 作者刘玲 前华为UCD中心交付经理 277169188qq.com 摘要: 本文演绎论证了当…

visual studio2008 OpenGL开发配置

visual studio2008发布已经很久了,但是Google了一下却没有多少篇文章讲关于配置OpenGL环境的,强大的visual studio2008已经非常人性化了,比起其他开发工具来说,visual studio2008的OpenGL配置实在太简单了,下面就setp …

postman mysql_postman连接mysql执行操作

postman也可以连接mysql目录1、安装2、启动服务3、执行sql语句1、安装想要postman连接mysql,需要安装xmysql,启动该服务,然后才可以调用。预置条件:完成nodejs和npm的安装安装xmsql:npm install -g xmysql2、启动服务启…

UEditor 插入图片大于2M提示文件大小超出范围解决办法

wordpress使用UEditor-KityFormula 编辑器时候插入图片的时候会提示附件大小超出范围等错误,这是因为UEditor编辑器里面有限制了图片附件大小最大不能超过2m的原因 解决办法要修改 插件 php里面的 config.json 文件 “scrawlMaxSize”: 2048000, /* 上传大小限制&am…

Real to Int

Round Round(123.243,0.05) {123.20} Trunc(123.23) {123} 转载于:https://www.cnblogs.com/lingdanglfw/archive/2008/07/14/1242233.html

jq-dom操作

相关概念 html DOM节点: jq对象: jq方法: 2.代码 $("#test").text("你好"); $("#test").html("你好"); 转载于:https://www.cnblogs.com/alan-alan/p/7204547.html

mysql提示太多连接_mysql数据库提示连接太多怎么办

mysql数据库提示连接太多的解决方法:1、登录mysql数据库,查看当前活动的连接线程变量值;2、编辑my.cnf配置文件,添加【[mysqld] port3306】;3、重启mysql服务器。解决方法:查看max_connections进入MySQL&am…

[MySQL FAQ]系列 -- 快速还原MyISAM表索引

作/译者:叶金荣(Email: ),来源:http://imysql.cn,转载请注明作/译者和出处,并且不能用于商业用途,违者必究。假设有个myisam表:tbl,为了备份方便,…

Android Studio 之 NDK篇

由于工作内容的关系,对于NDK的工作涉及比较广(保密性,安全性),所以本章内容讲述一下NDK的基本使用过程。 网上也有很多这样的教程或者描述,但描述的并不完全 开发工具:Android Studio 2.1.2 ND…

mysql codesmith_CodeSmith连接Mysql配置

1,首先需要将MySql.Data.dll复制到codesmith安装目录下v6.5/bin文件夹下,注意dll的版本2,其次采用的是.net4.0的配置文件,找到C:\Windows\Microsoft.Net\Framework\v4.0.30319\Config\machine在其中的DbPro…

避免一个用户多次登录修改版

原来的代码参见这里http://www.qiuhao.com//dispbbs.asp?boardID2&ID6228&page1 今天仔细看了这段代码,发现这段代码大有优化的余地 因为maxSessions 这个值可能会很大,我这里测试环境有3万多个,启动时要浪费半分钟左右 另外sessionId是个随机数,用1到maxSessions其实…

Maven工程 报 Diamond types are not supported at language level ‘5‘

选择file project Structure 1.Project – Project language level 选择8 2. Modules – Language level: 选择8

php excel导入mysql_PHP将Excel内容导入mysql数据库

//exp.php 用于导出include_once conn.php;$savename date("YmjHis");mysql_query("Set Names gbk");$file_type "vnd.ms-excel";$file_ending "xls";header("Content-Type: application/$file_type;charsetbig5");heade…

Ubuntu 16.04安装idea

此篇为http://www.cnblogs.com/EasonJim/p/7139275.html的分支页。 前提:必须正确安装JDK和Tomcat。 下载: https://www.jetbrains.com/idea/download/previous.html 这里可以下载社区版本,也可以下载以往历史版本。 安装过程: 解…

深表歉意

近期有许多读者朋友向我反应,他们在互动出版网、当当网、卓越网等大型IT书店中购买了《网管员必读》系列第二版时,在下订单后常常被告知有些图书缺货无法发货。本来就是想购买全套的,结果无奈地少了几本(如《网管员必读——网络应…

Error occurred while trying to proxy request

Error occurred while trying to proxy request /api/v1/ProveApplys/GetApplyTypes from 127.0.0.1:8010 to https://10.112.102.20:44321 (ETIMEDOUT) 解决方法: 清空浏览器缓存