Do you mean the featured image? Use wp_get_attachment_image
– Here is the code that I use in my plugin
while ( $the_query->have_posts() ) :$the_query->the_post();
$image_id = get_post_thumbnail_id();
$imagesize="thumbnail";
$image_url = wp_get_attachment_image_src($image_id, $imagesize, true);
//do something
endwhile;
You can also use wp_get_attachment_url( $id );