# How to copy an image given as a GraphicsBox expression to the clipboard?

I have a GraphicsBox expression encoding an image. I need to copy this image to the clipboard so that it can be inserted in a Microsoft Word document. When I invoke this command:

CopyToClipboard@GraphicsBox[
RasterBox[CompressedData["
1:eJwBMAPP/CFib1JmAgAAAHMIAAAAUmF3QXJyYXlTBAAAAEJ5dGViAwAAABAA
AAAQAAAAAwAAAOWJcN1+aq1DUL9UV89iX9JjYNBfXM1cWs9hXsJZXs5wauKE
bOSVdtCIc8FYW5lCU+iIbNx3Y6s/TMBRVdBeXc1fYspwcc6Gf8xpacNOVcpk
Z+OFctp2ZeylgZhIV1UNOsVaV9p0YaU8TbxOVclWWL1bYsVzdtirnuHDtbpr
c8dYW8xlZN5oXb5fXlgWP3gwT65HUNp1ZqQ6TL1RVr9TWcJbYcx3dtmon+LF
utnFvdJ3cqRFUsqIh3YqS2geRsuCfbhNUt17Z6Y4ScNcWcRaW8RcZNaJhOGj
l+GqntqzrNyrn92zptrBt2IgSLBgbNyRgb1QU+GAaKM1R8RjW9Z2ZsliacZq
daZefKJeddKbk9q5rN6vo5lVY3guUNqOhM6GfLxQVN9/aKU4SrpTVdh9b7RP
ZXcuXGQiWbB9jOO3psmMj5xNX18VO6hga9qWhs6Hf7ZMU92AbKY8TsVTVblZ
Y24nVV4bTbN1fMp+f+qil82Ih3MmS28nSsuEe82Lf8N+faxET96Ba7FEUKhW
Znk8bF4gVZBNX9GAfrRTZeCEhKROYXYpTI9GWtaMfcV+eMeKfZM1St5+aa5M
YnhCe2YoV386VptSX9ZkauqIg+SBgMRlb3YpSrJoasqDe82NePDEkZU3TeOE
caBCXnA5coZHbJZTYnknRdpdYN5qa+R/fZFAWH8xTM6Ed8F5dOOshfLTqYgw
SOeLdo47W2w6cqJpjngyTWQXPK1ATeJrbMdkcF0SO5VDVMuIe7l5durBmu/K
n41CV9+Dcns2V2oxZIhbjHM0WlwWPZI1S9ttbtqWipxlcJJBVLpxcq5pauKw
iZ5NVZZdbtyEcHIuUVwdS3pGd4RQdm4fP7dLVd5oZeSOfvHHsLFwc7t0cNid
gdKEbJk3TZNaat2IcXEsT1cYRHE7aWgtV4cqP81dXuBqZNpyaeu2pNKblJZJ
VNeXdK1RVI48VKRtddmKdWklS2UoVm84ZmwkSLFCSNpkXuBuZ91vZeWcjNir
o5pJVK5VVYo7U4M6U7TRiLk="], {{0, 16}, {16, 0}}, {0, 255},
ColorFunction -> RGBColor]]


and paste the clipboard contents to the document, it is displayed as a plain text, not an image.

How do I copy the corresponding image?

-
Nice image, by the way ;) –  Vladimir Reshetnikov Jun 22 '13 at 6:11
@VladimirReshetnikov Doesn't it actually try to reformat the disk? I mean it's a Run command, not just the image of a Run command, isn't it? –  Michael E2 Jul 12 '13 at 14:46
@MichaelE2 It is Run indeed, but it only invokes cmd to execute an echo command (i.e. print to console) to pretend it formats a disk: Run["cmd /k \"cd\\&&echo C:\\^>format C: /quick /force&&echo.&&echo WARNING, ALL DATA ON NON-REMOVABLE DISK&&echo DRIVE C: WILL BE LOST!&&echo.Proceed with Format (Y/N)? Y&&echo.&&echo Formatting...&&echo 100 percent completed.\""]. You see, format C: is just part of an input string to the echo command. I suppose it was just a friendly reminder not to run code from untrusted sources. –  Vladimir Reshetnikov Jul 12 '13 at 17:44
@VladimirReshetnikov Thanks for the clarification. I know epsilon about Windows. –  Michael E2 Jul 12 '13 at 19:17

This works for me:

boxes = ToBoxes@Graphics@Raster[RandomReal[{0, 1}, {5, 5}]]

(*
==> GraphicsBox[
RasterBox[{{0.0429951, 0.153342, 0.815801, 0.825589,
0.178414}, {0.732659, 0.659418, 0.871481, 0.644735,
0.54453}, {0.499096, 0.328874, 0.40405, 0.436912,
0.0551782}, {0.824125, 0.889256, 0.249706, 0.562126,
0.408294}, {0.612762, 0.153045, 0.145043, 0.555131, 0.820553}}]]
*)

CopyToClipboard@ToExpression@boxes

Paste[]


-