Why are you trying to store images in the DB? Do you have any good reason(s) for doing so? If not, then why not let the file system take care of files (like images) and instead use the database to store information about that file?
Otherwise, you insert and retrieve an image the same way you'd insert and retrieve any other data. Garbage in, garbage out.