the above code works for me both with jpg and png images. But from the title of your question I guess that you are not loading an ordinary png or jpg image, but instead a base64 encoded one.
Why are you loading a base64 encoded image? I do not think you will be able to view such an encoded image for instance with MS Paint either.
If you will just load a normal jpg or png with the code above and then do
You will see that the linked resource will be base64 encoded automatically, so you do not have to do it on your own beforehand.
If this is not the case and you really have the images in this format, let me know.