RGB与INT类型的转换
开发时遇到的问题,设置图层样式时颜色的返回值是uint,一时不知改怎么转换为C#常用的RGB值了。
一番百度,结果如下:
RGB = R + G * 256 + B * 256 * 256
因此可得到如下反推代码:
private Color To_RGB(int color)
{
int b = color / ( * );
int g = (color - b * * ) / ;
int r = color - b * * - g * ;
return Color.FromArgb(r, g, b);
}
网上还有位运算的快速算法:
private uint To_uint(Color color)
{
return (uint)(((uint)color.B << ) | (ushort)(((ushort)color.G << ) | color.R));
}
private Color To_RGB(int color)
{
int r = 0xFF & color;
int g = 0xFF00 & color;
g >>= ;
int b = 0xFF0000 & color;
b >>= ;
return Color.FromArgb(r, g, b);
}
并看不懂,但是能用。
RGB与INT类型的转换的更多相关文章
- 【转】java中byte数组与int类型的转换(两种方式)----不错
原文网址:http://blog.csdn.net/piaojun_pj/article/details/5903009 java中byte数组与int类型的转换,在网络编程中这个算法是最基本的算法, ...
- 总结:String类型与Int类型的转换【实现插入操作主键自增】
1.String类型(此类型是数字格式的字符串类型)转换成Int类型 String str = "10000"; 转换成Int类型: int num = Integer.parse ...
- mysql 查询 int类型日期转换成datetime类型
数据库日期类型是int类型的,该查询结果是datetime类型的 SELECT from_unixtime( `时间列名` ) FROM 表名 如果原来类型是datetime类型,查询结果要是int类 ...
- c#中RGB与int类型之间的转换
Color color = Color.FromArgb(0, 0, 255);int colorInt = ParseRGB(color); --------------------- int Pa ...
- String与Int类型的转换
http://blog.sina.com.cn/s/blog_4f9d6b1001000bfo.html int -> String int i=12345; String s="&q ...
- double与int类型自动转换
package com.abc.test; public class SumTest { public static void main(String[] args) { //题目A:2+4+6+8+ ...
- long类型与int类型的转换
在数据库中会出现,numberic转换为int出错 在网站中,提交form的时候出现long转int失败会报错,跌了两次坑,还有ajax提交的时候long转int会报错.
- java中byte数组与int类型的转换(两种方式)
http://blog.csdn.net/z69183787/article/details/38564219 http://blog.csdn.net/z69183787/article/detai ...
- 03.枚举和string以及int类型之间的转换
练习1: 将枚举类型强转成int类型 namespace _04.枚举类型的练习01 { //声明一个QQState类型的枚举 public enum QQState { OnLine, OffL ...
随机推荐
- QuantLib 金融计算——数学工具之求解器
目录 QuantLib 金融计算--数学工具之求解器 概述 调用方式 非 Newton 算法(不需要导数) Newton 算法(需要导数) 如果未做特别说明,文中的程序都是 Python3 代码. Q ...
- 使用GPIO监听中断
#include<stdlib.h> #include<stdio.h> #include<string.h> #include<unistd.h> # ...
- Go语言目录
为什么学习Go语言 第一章 环境搭建 Windows搭建Go语言环境 第二章 Go语言基础 Go语言介绍 Go语言命名 Go语言内置类型和函数 Go语言特殊函数介绍 Go语言运算符 第三章 Go语言程 ...
- Windows开发经验 - WinDbg
1. 远程调试 参考文章:https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/remode-debugging-usi ...
- Sublime 必知必会(持续更新)
1.格式化代码 Edit - Line - Reindent(中文路径则是:编辑 - 行 - 再次缩进) 2.分屏显示 view-layout-Columns:2(中文路径则是:查看 - 布局 - 列 ...
- Java异常机制关键字总结,及throws 和 throw 的区别
在Java的异常机制中,时常出现五个关键字:try , catch , throw , throws , finally. 下面将总结各个关键字的用法,以及throw和throws的区别: (1) t ...
- Springsecurity搭建自定义登录页面
1.springSecurity的搭建 新建一个springboot的web项目,我这边只选中了web,建立后如下: pom依赖: <!-- https://mvnrepository.com/ ...
- "Visual Studio Code is unable to watch for file changes in this large workspace"
https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-chang ...
- WPF在XAML中使用MultiBinding的两个例子
使用MultiBinding的原则:数据源有一个以上: 1. 需求:在一个需要显示的内容中,不同的部分要进行的处理不一样,这时可以使用MultiBinding <TextBlock> &l ...
- Java Inner Class 内部类
内部类 Inner Class 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. Java中的内部类共分为四种: 静态内部类static inner class ( ...