The way of converting might be correct, I wouldn't save images in a db though, it get's very bloated, put it in a servermap and save the location in the db.