I want to create image object when user selecting a file from html page.
How can i create image object for dynamic images. Can anybody share me the sample snippet .
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically:
You can create an
imgelement like any other element:createElement. (There’s alsonew Image()which is pretty much the same thing, just a legacy mechanism.)You can set its source by setting the
srcproperty, which can be afile://URL the user supplies……or you can let them choose via an
input type="file"element if their browser supports using the File API; see my answer to this other question for getting access to image data that way.You can put the
imgelement in the document by appending it to whatever other element you want to append it to, viaappendChildor related methods.You can find an existing element using
getElementById,getElementsByTagName, etc., or (on most browsers but not all)querySelector/querySelectorAll.In addition the various specifications linked inline above, you may also find the new work-in-progress HTML5 specification useful.