title: How to save image along with DPI information into clipboard?
body: <p>It looks like <strong><a href="https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setresolution(v=vs.110).aspx" rel="nofollow noreferrer">Bitmap.SetResolution()</a> has no effect on clipboard</strong>, see the following trivial code:</p>
  
   
  
  <pre class="lang-vb prettyprint-override"><code>Dim bitmap1 As Image = New System.Drawing.Bitmap(100, 100)
  Using gr As Graphics = Graphics.FromImage(bitmap1)
      gr.FillRectangle(System.Drawing.Brushes.Black, 0, 0, 99, 99)
      gr.FillRectangle(System.Drawing.Brushes.White, 10, 10, 89, 89)
  End Using
  
  bitmap1.SetResolution(150, 150)  
  
  Clipboard.SetImage(bitmap1)                              ' DPI not set
  bitmap1.Save("D:\bitmap1.png", imaging.ImageFormat.Png)  ' DPI set
  </code></pre>
  
  <p>The file contains correctly set image DPI. In the clipbaord, it is not present.</p>
  
  <p><strong>Proof:</strong>  In clipboard dump (image inserted into clipboard by IrfanView), see DIB bitmap header of <strong><code>60 × 120</code> DPI</strong> (yellow=horizontal DPI, green=vertical DPI):</p>
  
  <p><a href="https://i.stack.imgur.com/kev3Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kev3Y.png" alt="enter image description here"></a></p>
  
  <p>But after inserting image using <a href="/questions/tagged/.net" class="post-tag" title="show questions tagged &#39;.net&#39;" rel="tag">.net</a>'s <code>Clipboard.SetImage()</code>, both these numbers are <code>0</code>.</p>
  
  <p><strong>My goal:</strong> be able to paste image into Microsoft Word with proper size (taken from DPI and dimensions). Without DPI set in the clipboard, the image is <strong>too big</strong> after pasting. But it contains barcode already with 1 bar = 1 px resolution, so I cannot sample it down.</p>
  
  <p>How to verify DPI: Either by clipboard viewer OR by opening the image in image editor which shows image properties. If you have only Word, drag&amp;drop the image over the document. Image size of the above example should have been 1.69×1.69 cm – and if taken from file, it actually is. If from .NET-made clipboard, it isn't.</p>
  
  <p><strong>What I am missing in process of setting the image DPI?</strong></p>
  
  <p><em>(C# or VB, whatever you prefer.)</em></p>