Skip to content

Commit

Permalink
Add loadImage function
Browse files Browse the repository at this point in the history
  • Loading branch information
sekcompsci committed Oct 27, 2017
1 parent 43370b8 commit f253548
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions PieSketch/p5js/loadImage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. raw:: html

<script src="https://sketch.netpie.io/widget/p5-widget.js"></script>

loadImage()
===========

โหลดรูปภาพจากเส้นทางและสร้าง p5.Image จากไฟล์

ภาพอาจไม่สามารถใช้งานได้ทันทีสำหรับการแสดงผลหากคุณต้องการให้แน่ใจว่ารูปภาพพร้อมใช้งานแล้วก่อนที่จะทำอะไรให้ทำโหลด loadImage () ใน preload () นอกจากนี้คุณยังสามารถจัดหาฟังก์ชันการโทรกลับเพื่อจัดการกับภาพเมื่อพร้อม

เส้นทางไปยังรูปภาพต้องสัมพันธ์กับไฟล์ HTML ที่ลิงก์ในร่างของคุณ การโหลดรูปภาพจาก URL หรือสถานที่ห่างไกลอื่น ๆ อาจถูกบล็อกเนื่องจากความปลอดภัยภายในของเบราเซอร์ของคุณ

.. Loads an image from a path and creates a p5.Image from it.
.. The image may not be immediately available for rendering If you want to ensure that the image is ready before doing anything with it, place the loadImage() call in preload(). You may also supply a callback function to handle the image when it's ready.
.. The path to the image should be relative to the HTML file that links in your sketch. Loading an image from a URL or other remote location may be blocked due to your browser's built-in security.
**รูปแบบการใช้งาน**

loadImage(path,[successCallback],[failureCallback])

**พารามิเตอร์**

- ``path`` สตริง: เส้นทางของรูปภาพที่จะโหลด

- ``successCallback`` ฟังก์ชั่น (p5.Image): ฟังก์ชั่นที่จะเรียกเมื่อภาพถูกโหลด จะถูกส่งผ่าน p5.Image

- ``failureCallback`` ฟังก์ชัน (เหตุการณ์): เรียกว่ามีข้อผิดพลาดของเหตุการณ์ถ้าไม่สามารถโหลดภาพ

.. ``path`` String: Path of the image to be loaded
.. ``successCallback`` function(p5.Image): Function to be called once the image is loaded. Will be passed the p5.Image.
.. ``failureCallback`` Function(Event): called with event error if the image fails to load.
**ค่าที่ส่งออกมา**

- p5.Image: วัตถุ p5.Image

.. p5.Image: the p5.Image object
.. raw:: html

<script type="text/p5" data-autoplay data-hide-sourcecode>
var img;
function preload() {
img = loadImage("assets/laDefense.jpg");
}
function setup() {
image(img, 0, 0);
}
</script>

<br><br>

<script type="text/p5" data-autoplay data-hide-sourcecode>
function setup() {
// here we use a callback to display the image after loading
loadImage("assets/laDefense.jpg", function(img) {
image(img, 0, 0);
});
}
</script>

<br><br>

.. [#f1] This document was generated from p5.js whose source code is available on `github <https://github.com/processing/p5.js>`_.

0 comments on commit f253548

Please sign in to comment.