当前位置:网站首页>RGB color to hex and unit conversion
RGB color to hex and unit conversion
2022-04-23 07:54:00 【Dake mountain man】
RGB Color change HEX Base number :
function rgbToHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {
if (N==null) return "00";
N=parseInt(N); if (N==0 || isNaN(N)) return "00";
N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
return "0123456789ABCDEF".charAt((N-N%16)/16)
+ "0123456789ABCDEF".charAt(N%16);
}
function getColorStringFromRGB(r, g, b) {
return "#" + toHex(r) + toHex(g) + toHex(b);
}
c#:
public static string RgbToHex(int r, int g, int b)
{
return ToHex(r)+ToHex(g)+ToHex(b);
}
priavate string ToHex(int? N)
{
if (N==null || N==0) return "00";
N=Math.Max(0,N);
N=Math.Min(N,255);
N=Math.Round(N);
return "0123456789ABCDEF".charAt((N-N%16)/16)
+ "0123456789ABCDEF".charAt(N%16);
}
public static string ColorStringFromRGB(int r, int g, int b)
{
return "#" + RgbToHex(r, g, b);
}
// Spare below
function JSONBlocksToJSONArray(jsonBlocks) {
var jsonArray = '{';
var firstBlock = true;
for (var key in jsonBlocks) {
if (jsonBlocks.hasOwnProperty(key)) {
jsonArray += (firstBlock ? '' : ',') + '"' + key + '" : ' + jsonBlocks[key];
firstBlock = false;
}
}
jsonArray += '}';
return jsonArray;
}
//AI or PS JSON Color To RGB
convertColorToRGB : function (colorJSON) {
var pickerDesc = new ActionDescriptor();
pickerDesc.putBoolean( stringIDToTypeID( 'newDocPresetJSON'), true);
pickerDesc.putString( stringIDToTypeID( 'color' ), colorJSON);
pickerDesc.putEnumerated(stringIDToTypeID( 'colorSpace'), stringIDToTypeID( 'colorSpace'), stringIDToTypeID('RGB'));
var resultDesc = executeAction( stringIDToTypeID('convertColorToSpace'), pickerDesc, DialogModes.ALL );
return resultDesc.getString(stringIDToTypeID('color'));
}
function getRGBFromColorString(colorString) {
var r = 0,
g = 0,
b = 0;
try {
colorString = colorString.substr(colorString.indexOf("#") + 1); // Strip off '#'
// Ignore alpha
if (colorString.length > 6) {
colorString = colorString.substr(0, 6);
}
var val = parseInt(colorString, 16);
r = (val >> 16) & 255;
g = (val >> 8) & 255;
b = val & 255;
} catch (ignore) {}
return newRGB(r, g, b);
}
Unit conversion :
picasToPixels: function (picas) {
return Math.round(picas * 16);
}
cmToPixels: function (cms) {
return Math.round(cms * 37.79527559055);
}
inToPixels: function (inches) {
return Math.round(inches * 96.0000000000011);
}
mmToPixels: function (mm, resolution) {
var pt = mm * 2.83464566929134;
return pointsToPixels(pt, resolution);
}
pointsToPixels: function (pt, resolution) {
return Math.round((pt / 72) * resolution);
}
pixelsToPoints: function (px, resolution) {
return (px * 72) / resolution;
}
// Conversion for Points:
function ConvertUnitsToPoints(unitType, unitValue) {
if (unitType === MeasurementUnits.POINTS) {
return unitValue;
}
var pointsValue = unitValue;
switch (unitType) {
case MeasurementUnits.Q:
pointsValue = pointsValue * 0.7086614173228346;
break;
case MeasurementUnits.AMERICAN_POINTS:
pointsValue = pointsValue * (0.3514 / 25.4 * 72);
break;
case MeasurementUnits.MILLIMETERS:
pointsValue = (pointsValue * 72.0) / 25.4;
break;
case MeasurementUnits.HA:
pointsValue = pointsValue * 0.7086614173228346;
break;
case MeasurementUnits.BAI:
pointsValue = pointsValue * 6.336;
break;
case MeasurementUnits.U:
pointsValue = (pointsValue * 72.0 * 11.0) / 1000.0;
break;
case MeasurementUnits.MILS:
pointsValue = pointsValue * 0.072;
break;
case MeasurementUnits.PICAS:
pointsValue = pointsValue * 12.0;
break;
case MeasurementUnits.INCHES:
case MeasurementUnits.INCHES_DECIMAL:
pointsValue = pointsValue * 72.0;
break;
case MeasurementUnits.CENTIMETERS:
pointsValue = (pointsValue * 72.0) / 2.54;
break;
case MeasurementUnits.CICEROS:
pointsValue = pointsValue * 12.7878751998;
break;
case MeasurementUnits.AGATES:
pointsValue = (pointsValue * 72.0) / 14.0;
break;
case MeasurementUnits.PIXELS:
//No conversion required
break;
default:
//alert('convertUnitsToPoints: Unknown unitType');
break;
}
return pointsValue;
};
版权声明
本文为[Dake mountain man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230625378447.html
边栏推荐
- 解决在docker中部署mysql8, 密码正确但无法登陆MySQL问题
- The problem of exporting excel form with wireframe and internal spacing of form by using web form
- Houdini > rigid body, rigid body breaking RBD
- VBA調用SAP RFC實現數據讀取&寫入
- VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données
- Double sided shader
- Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
- Index locked data cannot be written to es problem handling
- Mongodb starts warning information processing
- Xamarin版的C# SVG路径解析器
猜你喜欢

Houdini fluid > > particle fluid export to unity note

平面定义-平面方程

Houdini > variable building roads, learning process notes

How to present your digital portfolio: suggestions from creative recruiters

C# 多个矩形围成的多边形标注位置的问题

About USB flash drive data prompt raw, need to format, data recovery notes

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

基于NLP的软件安全研究(二)

Common markdown grammar learning

Apache Hudi 如何加速传统的批处理模式?
随机推荐
c#读取INI文件和向ini文件写入数据
Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
Mongodb 启动警告信息处理
每天工作4小时的程序员
Encapsulate the debug function of unity
When using flash, the code ends automatically without an error, the connection cannot be maintained, and the URL cannot be accessed.
Houdini fluid > > particle fluid export to unity note
Mongodb starts warning information processing
Event system (II) multicast events
快速排序
The problem of exporting excel form with wireframe and internal spacing of form by using web form
IDEA快捷键
Shapley Explanation Networks
TimelineWindow
VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données
C operation registry full introduction
Gets the maximum getmaxpoint in the list of all points
Houdini > variable building roads, learning process notes
第七章 资产减值