brak możliwości wczytania plików jpg

0

Dzień dobry
Uczę się JS za pomocą https://thecodingtrain.com/beginners/p5js/7.8-objects-and-images.html tam jest problem z pobraniem pliku do wyszukiwarki

function preload() {
  flower = loadImage('kittens/flower.png');
  for (let i = 0; i < 5; i++) {
    kittens[i] = loadImage(`kittens/kitten${i}.jpg`);
  }
}

zarówno w chromie i firefox nie odpala ten kod pochodzi z platformy p5.js i też ma błąd. Pytanie jak wczytywać pliki jpg

0

Jaki błąd Ci się pokazuje?

Podaj jak najwięcej konkretów, screenshoty, wszystko.

0

F12, zakładka z konsolą, tam zobaczysz treść błędu. Przeczytaj ze zrozumieniem, popraw. Howgh.

0

p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/kitten0.jpg] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 810, … }
previewScripts.js82106
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/kitten1.jpg] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 811, … }
previewScripts.js82106
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/kitten3.jpg] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 815, … }
previewScripts.js82106
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/flower.png] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 816, … }
previewScripts.js82106
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/kitten2.jpg] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 821, … }
previewScripts.js82106
p5.js says: It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/kitten4.jpg] is correct, hosting the image online, or running a local server.[https://github.com/processing/p5.js/wiki/Local-server] previewScripts.js82106
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 821, … }
previewScripts.js82106

w drugim przyadku
p5.js:74522 Fetch API cannot load file:///C:/images/flower0.jpg. URL scheme must be "http" or "https" for CORS request.
_main.default.loadImage @ p5.js:74522
p5.js:74522 Fetch API cannot load file:///C:/images/flower1.jpg. URL scheme must be "http" or "https" for CORS request.
_main.default.loadImage @ p5.js:74522
p5.js:74522 Fetch API cannot load file:///C:/images/flower2.jpg. URL scheme must be "http" or "https" for CORS request.
_main.default.loadImage @ p5.js:74522
3p5.js:74522 Uncaught (in promise) TypeError: Failed to fetch
at p5._main.default.loadImage (p5.js:74522)
at p5.js:58778
at preload (sketch.js:7)
at p5._start (p5.js:58736)
at new p5 (p5.js:59080)
at _globalInit (p5.js:58340)

1

It looks like there was a problem loading your image. Try checking if the file path [https://editor.p5js.org/full/H44xHm5a/kittens/flower.png] is correct, hosting the image online

Ok, a czy spróbowałeś wejść na podany adres - np. https://editor.p5js.org/full/H44xHm5a/kittens/kitten3.jpg?

Bo ja spróbowałem i dostałem informację o treści message: "Asset does not exist". Skoro ten obrazek nie istnieje, albo może i istnieje, ale nie ma go pod podanym adresem, to czemu się dziwisz, że nie można go załadować? Zresztą komunikat błędu mówi o tym wprost - dany zasób jest nieosiągalny.

Fetch API cannot load file:///C:/images/flower0.jpg

Jak myślisz, czemu to nie chce się pobrać? Masz podaną ścieżkę do pliku zapisanego lokalnie na swoim dysku. Ktoś tak pewnie miał podczas tworzenia (co swoją drogą było kiepskim pomysłem, jakby podał adres względny to by problemu nie było podczas przenoszenia na serwer) i bezmyślnie przeniósł stronę z kompa na serwer. W takiej postaci to za bardzo nie ma prawa działać.

0

no własnie robiłem to na nodpadc++ i podałem ścieżkę z katalogu
``function preload() {

for (var i=0; i< 3; i++) {
	flower[i] = loadImage('images/flower' + i + '.jpg');
}
``

pliki istnieją tylko mam jakiś bład

1

pliki istnieją tylko mam jakiś bład

Sam wkleiłeś jego treść. Treść ta zawiera nawet rozwiazanie, wystarczy przeczytać ze zrozumieniem.

"p5.js:74522 Fetch API cannot load file:///C:/images/flower0.jpg. URL scheme must be "http" or "https" for CORS request."

1 użytkowników online, w tym zalogowanych: 0, gości: 1