java - Load online images in <img> tag with itext -
i'm using xmlworker
in itextpdf library convert xhtml pdf.
in xhtml content there tag local storage images , images internet.
eg:
<img src="https://www.w3schools.com/images/w3schools_green.jpg" alt="w3schools.com" style="width:104px;height:142px;"/>
with local images, have implemented imageprovider
provide resource root path. these images internet, cannot loaded.
i tried override image retrieve(string src)
method of abstractimageprovider load images internet, got networkonmainthread
exception. don't know how use asynctask or other wars load online images , return inside image retrieve(string src)
.
i've searched in internet , people use imageprovider
local images. ideas me?
i don't understand question without context. may fit question.
create callback inside imageprovider
. every time asynctask
(or helps make request) gives response, trigger it.
public class imageprovider { private onimageprovidercallback callback; public imageprovider(onimageprovidercallback callback) { this.callback = callback; } public onimageprovidercallback getcallback() { return callback; } public void setcallback(onimageprovidercallback callback) { this.callback = callback; } public interface onimageprovidercallback { void onretrievedimage(image image); } public void retrive() { new asynctask<void, void, image>() { @override protected image doinbackground(void... voids) { // request image here if(request.success()) { return request.getimage(); }else{ // handle error return null; } } @override protected void onpostexecute(image image) { super.onpostexecute(image); callback.onretrievedimage(image); } }.execute(); } }
then in activity
, make done calling this
new imageprovider(new imageprovider.onimageprovidercallback() { @override public void onretrievedimage(image image) { // image } });
Comments
Post a Comment