{"id":4055,"date":"2016-08-03T11:17:05","date_gmt":"2016-08-03T03:17:05","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4055"},"modified":"2016-08-03T11:24:04","modified_gmt":"2016-08-03T03:24:04","slug":"fmx-fmx-multiresbitmap-%e7%9a%84%e4%b8%80%e5%a4%84%e6%94%b9%e8%bf%9b","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4055","title":{"rendered":"[FMX] FMX.MultiResBitmap \u7684\u4e00\u5904\u6539\u8fdb"},"content":{"rendered":"<p><a href=\"http:\/\/blog.sina.com.cn\/u\/1157240623\">\u7ea2\u9c7c\u513f<\/a>\u5728\u5176\u535a\u5ba2\u4e2d\u53d1\u8868\u7684<a href=\"http:\/\/blog.sina.com.cn\/s\/blog_44fa172f0102w618.html\">\u4e00\u7bc7\u6587\u7ae0<\/a>\u4e2d\u5f15\u8ff0\u4e86\u5b98\u65b9QC\u4e2d\u7684\u4e00\u5904\u7f3a\u9677\u62a5\u544a\uff0c\u8c08\u5230\u4e86 TCustomMultiResBitmap.ItemByScale \u7684\u6548\u7387\u95ee\u9898\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4f18\u5316\u3002\u4e0d\u8fc7\u6211\u89c9\u5f97\u5b83\u7684\u4f18\u5316\u6709\u70b9\u592a\u5077\u61d2\u4e86\uff0c\u800c\u4e14\u4e00\u65e6\u4e0d\u5339\u914d\uff0c\u6548\u7387\u8fd8\u4e0d\u5982\u539f\u6765\u7684\u5b9e\u73b0\u3002\u6240\u4ee5\u6211\u7b80\u5355\u5ba1\u89c6\u4e86\u4e0b ItemByScale \u7684\u4ee3\u7801\uff0c\u5b9e\u9645\u4e0a\u5b83\u7684\u6548\u7387\u95ee\u9898\u5728\u4e8e\u8fc7\u5ea6\u4f18\u5316\u9020\u6210\u4e86\u8d1f\u4f18\u5316\u3002\u5982\u679c\u5728\u63d0\u4f9b\u7684\u56fe\u7247\u7279\u522b\u591a\uff08\u6bd4\u5982\u6210\u767e\u4e0a\u5343\u4e2a\uff09\uff0c\u5b83\u8fdb\u884c\u4e00\u904d\u6bd4\u8f83\u5e76\u6392\u5e8f\u8fd8\u662f\u6709\u610f\u4e49\u7684\uff0c\u4f46\u73b0\u5b9e\u662f\u6211\u4eec\u6bcf\u4e2a\u7a0b\u5e8f\u4e2d\u5b9e\u9645\u4f7f\u7528\u7684\u56fe\u6570\u91cf\u662f\u6709\u9650\u7684\uff0c\u4e00\u822c\u53ea\u6709\u51e0\u4e2a\uff0c\u7528\u6392\u5e8f\u540e\u518d\u6bd4\u8f83\u7684\u7b97\u6cd5\u660e\u663e\u662f\u8fc7\u5ea6\u7684\u4f18\u5316\u53cd\u800c\u964d\u4f4e\u4e86\u6548\u7387\uff08\u6211\u4e5f\u6ca1\u5c11\u5e72\u8fd9\u4e8b:-:\uff09\u3002<\/p>\n<p>\u8bf4\u4e86\u4eba\u5bb6\u90a3\u4e48\u591a\uff0c\u4e0d\u63d0\u4f9b\u4e00\u4e2a\u81ea\u5df1\u7684\u5b9e\u73b0\u597d\u8c61\u8bf4\u4e0d\u8fc7\u53bb\u3002\u5b9e\u9645\u4e0a\u6211\u60f3\u63d0\u4f9b\u4e00\u4e2a\u5e26\u7f13\u5b58\u7684\u7248\u672c\uff0c\u540e\u6765\u89c9\u5f97\u5148\u4e0d\u5f97\u4e86\uff0c\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u6539\u8fdb\u7248\u672c\u5427\uff0c\u8fd9\u4e2a\u7248\u672c\u5728\u6d4b\u8bd5\u7684\u51e0\u79cd\u60c5\u51b5\u4e0b\u90fd\u660e\u663e\u4f18\u4e8e\u539f\u6765\u7684\u5b9e\u73b0\uff0c\u4e00\u822c\u662f\u57284-10\u500d\u5de6\u53f3\u3002<\/p>\n<pre class=\"lang:delphi decode:true \">function TCustomMultiResBitmap.ItemByScale(const AScale: Single;\r\n  const ExactMatch: Boolean; const IncludeEmpty: Boolean): TCustomBitmapItem;\r\nvar\r\n  LScale, LCurrentScale: Single;\r\n  I, LCount: Integer;\r\n  \/\/Added by swish\r\n  LDelta,LMinDelta: Single;\r\n  AItem: TCustomBitmapItem;\r\n  \/\/Comment by swish\r\n\/\/  LScaleArray: TArray&lt;Single&gt;;\r\nbegin\r\n  LScale := RoundTo(AScale, TCustomBitmapItem.ScaleRange);\r\n  Result := nil;\r\n  if not ExactMatch then\r\n  begin\r\n    \/\/Replaced by swish\r\n      LCount:=-1;\r\n      LMinDelta:=MaxInt;\r\n      for I := 0 to Count - 1 do\r\n      begin\r\n      AItem:=Items[I];\r\n      if (not IncludeEmpty) and AItem.IsEmpty then\r\n        Continue;\r\n      LDelta:=AItem.Scale-LScale;\r\n      if LDelta&lt;0 then\r\n        LDelta:=-LDelta;\r\n      if LDelta&lt;LMinDelta then\r\n        begin\r\n        LMinDelta:=LDelta;\r\n        LCount:=I;\r\n        if (LMinDelta=0) or ((LMinDelta&gt;0) and (LMinDelta&lt;TEpsilon.Scale)) then\r\n          Break\r\n        end;\r\n      end;\r\n      if LCount&gt;=0 then\r\n        Result:=Items[LCount];\r\n      Exit;\r\n\r\n    \/\/Follow is origin codes\r\n\/\/     LScaleArray := ScaleArray(IncludeEmpty);\r\n\/\/     LCount := Length(LScaleArray);\r\n\/\/     if LCount &gt; 0 then\r\n\/\/     begin\r\n\/\/       I := -1;\r\n\/\/       repeat\r\n\/\/       Inc(I)\r\n\/\/       until (LScale &lt; LScaleArray[I]) or (I &gt;= LCount - 1);\r\n\/\/       if I &gt; 0 then\r\n\/\/       begin\r\n\/\/       LCurrentScale := LScaleArray[I - 1] + (LScaleArray[I] - LScaleArray[I - 1]) \/ 5;\r\n\/\/       if LScale &lt;= LCurrentScale then\r\n\/\/       Dec(I);\r\n\/\/       end;\r\n\/\/       LScale := LScaleArray[I];\r\n\/\/     end;\r\n\r\n  end;\r\n  for I := 0 to Count - 1 do\r\n    if SameValue(LScale, Items[I].Scale, TEpsilon.Scale) and\r\n      (IncludeEmpty or (not Items[I].IsEmpty)) then\r\n    begin\r\n      Result := Items[I];\r\n      Exit;\r\n    end\r\nend;<\/pre>\n<p>\u4f7f\u7528\u65b0\u7684 TCustomMultiResBitmap \u7684\u65b9\u6cd5\u53c2\u8003<a href=\"http:\/\/blog.sina.com.cn\/s\/blog_44fa172f0102w618.html\">\u7ea2\u9c7c\u513f\u7684\u539f\u535a\u5ba2<\/a>\uff0c\u6211\u5c31\u4e0d\u591a\u8bf4\u4e86\u3002\u5b9e\u9645\u4e0a\uff0c\u5982\u679c\u8fdb\u4e00\u6b65\u4f18\u5316\u7684\u8bdd\uff0c\u5b98\u65b9\u5e94\u8be5\u5c06SameValue \u6539\u6210\u5185\u8054\uff0c\u53e6\u5916\uff0c\u8c61 Items[I] \u00a0\u8fd9\u79cd\u672c\u8d28\u4e0a\u5bf9\u51fd\u6570\u7684\u8c03\u6574\u8fd8\u662f\u5e94\u8be5\u7f13\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u91cc\u3002\u771f\u6b63\u5f7b\u5e95\u7684\u4f18\u5316\u6700\u597d\u5c31\u662f\u5728\u7ef4\u62a4\u4e0d\u540c\u5206\u8fa8\u7387\u56fe\u7247\u65f6\uff0c\u5185\u90e8\u6309\u7f29\u653e\u6bd4\u4f8b\u8fdb\u884c\u6392\u5e8f\uff0c\u8fd9\u6837\u5728\u8fd9\u91cc\u5c31\u53ef\u4ee5\u76f4\u63a5\u4e8c\u5206\u627e\u5230\u6700\u63a5\u8fd1\u7f29\u653e\u6bd4\u7684\u56fe\u7247\u4e86\uff0c\u4e0d\u8fc7\u90a3\u4e2a\u7559\u7ed9\u5b98\u65b9\u53bb\u6539\u5427\u3002\u8bf4\u4e0d\u5b9a\u5b98\u65b9\u6709\u66f4\u597d\u7684\u7b97\u6cd5\u5462\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ea2\u9c7c\u513f\u5728\u5176\u535a\u5ba2\u4e2d\u53d1\u8868\u7684\u4e00\u7bc7\u6587\u7ae0\u4e2d\u5f15\u8ff0\u4e86\u5b98 [&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":[145,69,8,602,21],"tags":[149,659,658,660],"class_list":["post-4055","post","type-post","status-publish","format-standard","hentry","category-android","category-c-builder","category-delphi","category-ios","category-misc","tag-fmx","tag-itembyscale","tag-tcustommultiresbitmap","tag-660"],"views":4884,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4055","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=4055"}],"version-history":[{"count":2,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4055\/revisions"}],"predecessor-version":[{"id":4057,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4055\/revisions\/4057"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}