Inserting picture programmatically

Hi

When you insert a picture in a rich text field using Create → Picture, the picture is not embedded as a file attachment but as an opened picture. Is there a way how to do this programatically?

Thanks

Ed