{"id":1343,"date":"2014-11-28T22:52:07","date_gmt":"2014-11-28T14:52:07","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=1343"},"modified":"2014-11-28T22:52:34","modified_gmt":"2014-11-28T14:52:34","slug":"%e5%91%a8%e6%9c%ab%e7%a6%8f%e5%88%a9web%e6%a0%bc%e5%bc%8f%e4%b8%8etcolor%e7%b1%bb%e5%9e%8b%e7%9a%84%e8%bd%ac%e6%8d%a2%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=1343","title":{"rendered":"Web\u683c\u5f0f\u4e0eTColor\u7c7b\u578b\u7684\u8f6c\u6362\u51fd\u6570"},"content":{"rendered":"<p>\u652f\u6301#RRGGBB\u6837\u5f0f\u7684Web\u5b57\u7b26\u4e32\u989c\u8272\u683c\u5f0f\u7684\u989c\u8272\u503c\u548cTColor\u4e4b\u95f4\u8fdb\u884c\u76f8\u4e92\u8f6c\u6362\uff0c\u4eceWeb\u989c\u8272\u683c\u5f0f\u8f6c\u6362\u4e3aTColor\u7c7b\u578b\u7684\u503c\u65f6\uff0c\u652f\u6301\u7701\u7565\u524d\u9762\u7684#\u53f7\u3002<\/p>\n<pre class=\"lang:delphi decode:true\">type\r\nTRGBAColor = record\r\n case Integer of\r\n 0:\r\n (Red, Green, Blue, Alpha: Byte);\r\n 1:\r\n (Color: TColor);\r\n end;\r\n\/\/\u4eceTColor\u5230Web\u989c\u8272\u683c\u5f0f\r\nfunction FormatWebColor(AColor: TColor): String;\r\nvar\r\n  ARef: TRGBAColor absolute AColor;\r\nbegin\r\nResult := '#' + IntToHex(ARef.Red, 2) + IntToHex(ARef.Green, 2) +\r\n  IntToHex(ARef.Blue, 2);\r\nend;\r\n\r\n\/\/\u4eceWeb\u989c\u8272\u683c\u5f0f\u8f6c\u6362\u4e3aTColor\r\nfunction FromWebColor(const S: String): TColor;\r\nvar\r\n  p: PWideChar;\r\n  R, G, B: Integer;\r\nbegin\r\np := PWideChar(S);\r\nif p^ = '#' then\r\n  Inc(p);\r\nResult := clNone;\r\nif TryStrToInt('$' + Copy(p, 0, 2), R) then\r\n  begin\r\n  Inc(p, 2);\r\n  if TryStrToInt('$' + Copy(p, 0, 2), G) then\r\n    begin\r\n    Inc(p, 2);\r\n    if TryStrToInt('$' + Copy(p, 0, 2), B) then\r\n      Result := RGB(R, G, B);\r\n    end;\r\n  end;\r\nend;<\/pre>\n<p>\u7528\u6cd5\u5f53\u7136\u8db3\u591f\u7b80\u5355\uff0c\u5982 FromWebColor(&#8216;#FF0000&#8217;)\u76f4\u63a5\u5c31\u662f\u7ea2\u8272\uff0cFormatWebColor(clRed)\u5f97\u5230\u7684\u7ed3\u679c\u5c31\u662f\u5b57\u7b26\u4e32#FF0000\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u652f\u6301#RRGGBB\u6837\u5f0f\u7684Web\u5b57\u7b26\u4e32\u989c\u8272 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,21],"tags":[196,47,197],"class_list":["post-1343","post","type-post","status-publish","format-standard","hentry","category-delphi","category-misc","tag-web","tag-47","tag-197"],"views":3752,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1343"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1343\/revisions"}],"predecessor-version":[{"id":1345,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1343\/revisions\/1345"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}