How to add an image field to a programmatically created form? Basically I want to create a block with my module which's edit page has a few content fields and two image upload fields. When visiting the node where this block is rendered, I want to render the images with a certain image style, while on the edit form it would be cool to show the images as a thumbnail preview.

I am adding a field like described here: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#managed_file but this makes me curious:


  New files are uploaded with a status of 0 and are treated as temporary
  files which are removed after 6 hours via cron. Your module is
  responsible for changing the $file objects status to
  FILE_STATUS_PERMANENT and saving the new status to the database.


Also, what is the difference of managed_file and file when I want to provide an image upload field?

Currently I have in hook_block_configure:

$form['left']['image'] = array(
        '#type' =&gt; 'managed_file',
        '#title' =&gt; 'test',
    );


Where do I define how this image shall be rendered (image style)? Do I have to set that permanent flag?

Thanks
You cannot use fields from the Field API in forms of the Form API directly, as Fields can be used directly in entities, and entities can be used directly with forms. 

Instead, you can use the approach described here, as Clive kindly pointed out. Alternatively, you can use ctools_field_invoke_field() function of CTools module too.

The two fields 'file' and 'managed_file' of the Form API are similar, with the difference that the latter provides a progress upload widget. Also, managed_file will add the file entry to a table with the same name. Beyond that, there is some work involved in order to render the file on a page, and that is not the imagefield of the Field API.