2017-09-05 48 views
1

我想加載保存在畫布上的svg,以便我可以修改並再次保存。所以我得到的隱藏字段的陣列,並加載該數組中的畫布:在畫布上在第二次刷新瀏覽器後在畫布上加載svg圖像

<input type="hidden" name="insert_arry" value='<?=htmlspecialchars($get_result[$insert])?>' id="insert_arry"> 
// script for loading the json array of svg on canvas 
// loading the view of canvas here 
opc_Canvas_Load(
    opc_View[opc_Current_View].path.replace('thumb','large'), 
    opc_Current_View 
); 
responsive_slide('opc_Product_Slider', 'pWrapper'); 
jq(window).resize(function() { 
    opc_Canvas_Load(opc_OverlayImg, opc_Current_View); 
}); 

// tried to load the div first of canvas using jquery, won't work 
$(".handler-area").first().css('display', 'block'); 

// getting the array stored in to the hidden field 
var insert_arry = jq('#insert_arry').val(); 

// loading the json array in canvas 
canvas.loadFromJSON(insert_arry.substring(1, insert_arry.length - 1)); 

對象加載,但它顯示了在瀏覽器中刷新圖像。這可能是圖像加載問題,但無法找到確切的解決問題。

+0

'loadFromJSON'來自fabric.js庫?你可以添加一個[MCVE],其中包含一些代替'<= = htmlspecialchars($ get_result [$ insert])?>'的最小數據。 – Kaiido

+0

[{「objects」:[],「background」:「」,「backgroundImage」:{「type」:「image」,「originX」:「left」,「originY」:「top」,「left」 0, 「頂部」:0, 「寬度」:1200, 「高度」:960, 「填充」: 「RGB(0,0,0)」, 「行程」:NULL, 「strokeWidth」:1, 「strokeDashArray」 :NULL, 「strokeLineCap」: 「對接」, 「strokeLineJoin」: 「斜切」, 「strokeMiterLimit」:10 「將scaleX」:1, 「的scaleY」:1, 「角度」:0 「flipX」:假」 flipY「:false}] – Harsh

+0

它的太大陣列,所以我不能把所有內容放在數組中..我只是縮短了數組內容。 – Harsh

回答

1
// Wow ... Aftera lot of try i m done with this task 
///// working code 

var insert_arry = jq('#insert_arry').val(); 
canvas.loadFromJSON(insert_arry.substring(1, insert_arry .length-1)); 
var img = new Image(); img.onload = function() { 
opc_Canvas_Load(opc_View[opc_Current_View].path.replace(‌​'thumb', 'large'), 
opc_Current_View); responsive_slide('opc_Product_Slider', 'pWrapper'); 
jq(window).resize(function() { opc_Canvas_Load(opc_OverlayImg, opc_Current_View); }); } 

尼斯!!!!!

相關問題