亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

在本教程中,我們將學習如何使用 FabricJS 刪除 IText 對象的 URL 字符串中的當前對象變換(縮放、角度、翻轉、傾斜)。 IText 類是在 FabricJS 版本 1.4 中引入的,它擴展了 Fabric.Text 并用于創建 IText 實例。 IText 實例使我們可以自由選擇、剪切、粘貼或添加新文本,而無需額外配置。還有各種支持的按鍵組合和鼠標/觸摸組合使文本具有交互性,而 Text 中未提供這些組合。

然而,基于 IText 的 Textbox 允許我們調整文本矩形的大小并自動換行。對于 IText 來說情況并非如此,因為高度不會根據換行進行調整。我們可以通過使用各種屬性來操作 IText 對象。同樣,我們可以使用 withoutTransform 屬性來刪除 IText 對象的 URL 字符串中當前對象的變換。

語法

toDataURL({ withoutTransform: Boolean }: Object): String

登錄后復制

參數

    選項(可選) – 此參數是一個對象,它為 IText 對象的 URL 表示形式提供額外的自定義。使用此參數可以更改高度、質量、格式和許多其他屬性,其中 withoutTransform 是一個屬性。

    選項鍵

      withoutTransform – 該屬性接受一個布爾值,它允許我們擺脫當前的對象變換。向其傳遞真值后,最終輸出圖像中將不再存在比例、角度、翻轉或傾斜。

      示例 1

      使用 withoutTransform 屬性并向其傳遞一個 false 值

      讓我們看一個代碼示例,看看向 withoutTransform 屬性傳遞 false 值時的輸出圖像。一旦我們從開發工具打開控制臺,我們就可以看到 IText 對象的 URL 表示。我們可以復制該 URL 并將其粘貼到新選項卡的地址欄中以查看最終輸出。在此示例中,我們向 IText 對象傳遞了指定垂直比例因子的scaleY 屬性。因此我們的輸出將垂直縮放。但是,由于我們還向 withoutTransform 屬性傳遞了一個 false 值,因此我們的最終輸出圖像仍將包含 scaleY 屬性。

      <!DOCTYPE html>
      <html>
      <head>
         <!-- Adding the Fabric JS Library-->
         <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
      </head>
      <body>
         <h2>Using the withoutTransform property and passing it a false value</h2>
         <p>You can open console from dev tools and see the output URL. You can copy that and paste it in the address bar of a new tab to see that the final image contains vertical scaling </p>
         <canvas id="canvas"></canvas>
      
         <script>
            // Initiate a canvas instance
            var canvas = new fabric.Canvas("canvas");
            canvas.setWidth(document.body.scrollWidth);
            canvas.setHeight(250);
      
            // Initiate a shadow object
            var shadow = new fabric.Shadow({
               blur: 25,
               color: "grey",
               offsetX: 12,
               offsetY: 15,
            });
      
            // Initiate an itext object
            var itext = new fabric.IText(
               "Add sample text here.Lorem ipsum dolor sit amet consectetur adipiscing.",{
                  width: 300,
                  left: 60,
                  top: 70,
                  fill: "#c70039",
                  backgroundColor: "#c1dfed",
                  stroke: "#c70039",
                  originX: "center",
                  shadow: shadow,
                  scaleY: 2,
               }
            );
      
            // Add it to the canvas
            canvas.add(itext);
      
            // Using the toDataURL method
            console.log(
               itext.toDataURL({ withoutTransform: false })
            );
         </script>
      </body>
      </html>
      

      登錄后復制

      示例 2

      使用 withoutTransform 屬性并向其傳遞一個真值

      讓我們看一個代碼示例,看看當使用 withoutTransform 屬性并向其傳遞 true 值時,IText 對象的最終輸出圖像是什么樣子。在這種情況下,我們的最終輸出圖像將不包含任何對象變換。

      <!DOCTYPE html>
      <html>
      <head>
         <!-- Adding the Fabric JS Library-->
         <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
      </head>
      <body>
         <h2>Using the withoutTransform property and passing it a true value</h2>
         <p>You can open console from dev tools and see the output URL. You can copy that and paste it in the address bar of a new tab to see that the final image does not contain vertical scaling </p>
         <canvas id="canvas"></canvas>
      
         <script>
            // Initiate a canvas instance
            var canvas = new fabric.Canvas("canvas");
            canvas.setWidth(document.body.scrollWidth);
            canvas.setHeight(250);
      
            // Initiate a shadow object
            var shadow = new fabric.Shadow({
               blur: 25,
               color: "grey",
               offsetX: 12,
               offsetY: 15,
            });
      
            // Initiate an itext object
            var itext = new fabric.IText(
               "Add sample text here.Lorem ipsum dolor sit amet consectetur adipiscing.",{
                  width: 300,
                  left: 60,
                  top: 70,
                  fill: "#c70039",
                  backgroundColor: "#c1dfed",
                  stroke: "#c70039",
                  originX: "center",
                  shadow: shadow,
                  scaleY: 2,
               }
            );
      
            // Add it to the canvas
            canvas.add(itext);
      
            // Using the toDataURL method with withoutTransform
            console.log(
               itext.toDataURL({ withoutTransform: true })
            );
         </script>
      </body>
      </html>
      

      登錄后復制

      以上就是如何使用 FabricJS 刪除 IText 對象的 URL 字符串中的當前對象轉換?的詳細內容,更多請關注www.92cms.cn其它相關文章!

分享到:
標簽:刪除 如何使用 字符串 對象 轉換
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定