ในกรณีของฉัน ฉันได้ใส่โค้ดสีบางไทล์ในไคลเอนต์ HTML และฉันต้องการเพิ่มคีย์โค้ดสีแบบธรรมดา ฉันมีไฟล์ PNG ที่ฉันต้องการใช้
ฉันไม่ต้องการความสามารถในการอัปโหลดหรือเปลี่ยนภาพ
ลิงก์นี้ดูเหมือนว่าจะบรรลุสิ่งที่ฉันกำลังมองหา แต่ฉันไม่แน่ใจว่าจะต้องนำไปใช้ที่ไหน โค้ดทั้งหมดนี้เข้าไปใน PostRender ของ Image Control ที่ฉันสร้างขึ้นหรือไม่
เพิ่มรูปภาพลงใน lightswitch โดยใช้คุณสมบัติในเครื่องและตำแหน่งไฟล์ ก>
นี่คือสิ่งที่ PostRender ของรายการข้อมูล Image แบบง่ายที่ฉันสร้างเป็น Image Local Property จากนั้นลากไปยัง Solution Designer โดยพื้นฐานแล้วมันถูกคัดลอกมาจากลิงก์ด้านบน แต่ฉันเปลี่ยนชื่อไฟล์รูปภาพให้ตรงกับของฉัน และฉันได้เพิ่มรายการลงในโครงสร้างโฟลเดอร์ Content\Images แล้ว และรายการดังกล่าวจะแสดงในมุมมองไฟล์:
myapp.BrowseOrderLines.ColorKey_postRender = function (element, contentItem) {
// Write code here.
function GetImageProperty(operation) {
var image = new Image();
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
// XMLHttpRequest used to allow external cross-domain resources to be processed using the canvas.
// unlike crossOrigin = "Anonymous", XMLHttpRequest works in IE10 (important for LightSwitch)
// still requires the appropriate server-side ACAO header (see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image)
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var url = URL.createObjectURL(this.response);
image.onload = function () {
URL.revokeObjectURL(url);
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
var dataURL = canvas.toDataURL("image/png");
operation.complete(dataURL.substring(dataURL.indexOf(",") + 1));
};
image.src = url;
};
xhr.open('GET', this.imageSource, true);
xhr.responseType = 'blob';
xhr.send();
};
myapp.BrowseOrderLines.ColorKey_postRender = function (element, contentItem) {
// Write code here.
msls.promiseOperation
(
$.proxy(
GetImageProperty,
{ imageSource: "content/images/Key.png" }
)
).then(
function (result) {
contentItem.screen.ImageProperty = result;
}
);
};
}
ปัจจุบัน ตัวควบคุมรูปภาพแสดงบนหน้าจอในเบราว์เซอร์ และเป็นขนาดแบบกำหนดเองที่ฉันเลือก แต่เป็นเพียงพื้นที่สีฟ้าอ่อนที่ไม่แสดงไฟล์รูปภาพของฉัน
ฉันไม่แน่ใจว่าฉันฝังภาพไว้หรือเปล่า? ฉันไม่แน่ใจว่านั่นเป็นขั้นตอนที่หายไปหรือไม่?
ขอบคุณ!!