title: How to transfer a scanned image from WIA ImageFile to TBitmap without saving it to disk?
body: <p>I'm using this code to acquire the scanned image from WIA:</p>
  
  <pre><code>const
    wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}';
    wiaFormatPNG = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}';
  var
    CommonDialog: ICommonDialog;
    AImage: IImageFile;
    i: Integer;
  begin
    CommonDialog := CreateOleObject('WIA.CommonDialog') as ICommonDialog;
  
    for i := 1 to Scanner.Properties.Count do
    begin
      if (Scanner.Properties[i].Name = 'Horizontal Resolution') or
        (Scanner.Properties[i].Name = 'Vertical Resolution') then
        Scanner.Properties[i].Set_Value(72)
      else if Scanner.Properties[i].Name = 'Horizontal Extent' then
        Scanner.Properties[i].Set_Value(Round(8.27 * 72))
      else if Scanner.Properties[i].Name = 'Vertical Extent' then
        Scanner.Properties[i].Set_Value(Round(11.00 * 72));
    end;
    AImage := IUnknown(CommonDialog.ShowTransfer(Scanner, wiaFormatPNG, True)) as IImageFile;
    //Save the image
    AImage.SaveFile('D:\1.' + AImage.FileExtension);
    imgImage.Picture.LoadFromFile('D:\1.' + AImage.FileExtension);
    DeleteFile('D:\1.' + AImage.FileExtension);
  end;
  </code></pre>
  
  <p><code>Scanner</code> is initialized using this code:</p>
  
  <pre><code>Scanner := DevMgr.DeviceInfos[Integer(cbWIASource.Items.Objects[cbWIASource.ItemIndex])].Connect.Items[1];
  </code></pre>
  
  <p>And <code>DevMgr</code> and <code>cbWIASource</code> are initialized using this code:</p>
  
  <pre><code>DevMgr := CreateOleObject('WIA.DeviceManager') as IDeviceManager;
  for i := 1 to DevMgr.DeviceInfos.Count do
      for j := 1 to DevMgr.DeviceInfos[i].Properties.Count do
        if DevMgr.DeviceInfos[i].Properties[j].Name = 'Name' then
        begin
          cbWIASource.Items.AddObject(DevMgr.DeviceInfos[i].Properties[j].Get_Value, TObject(i));
          Break;
        end;
  </code></pre>
  
  <p>I was wondering if there is a way to copy the scanned document without first saving it to the disk. I read on MSDN that I can access <code>ARGBData</code> member of <code>ImageFile</code> to access pixel data, but is there a simple way to copy the entire image from <code>FileData</code> to <code>TBitmap</code>? For instance, can I use a <code>TMemoryStream</code>?</p>
  
  <hr>
  
  <p>Just as an update, I found <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms630826%28v=vs.85%29.aspx#SharedSample001" rel="nofollow">this example</a> on MSDN. I know nothing about VB, but I guess the <code>Picture</code> object is a wrapper around <code>HBITMAP</code>. So, is it logical to conclude that the <code>ImageFile.Picture</code> property is what I need?</p>