title: Creating imagine from Memorystream using FromStream gives out of memory error
body: <p>I have a simple implemententation to create an imagine from a btye[] array using System.Drawing.Image.FromStream.  See below:</p>
  
  <pre><code>Using ms As System.IO.MemoryStream = New System.IO.MemoryStream(Convert.FromBase64String(Value), 0, Convert.FromBase64String(Value).Length)
  
         Dim img As System.Drawing.Image
         img = System.Drawing.Image.FromStream(ms)
         eRow.Properties.Value = img
  End Using
  </code></pre>
  
  <p>This does work most of the time.  Now and then I get an error 'out of memory' error trying to load the exact same imagine.</p>
  
  <p>Message: Out of memory.  Stack:    at System.Drawing.Graphics.CheckErrorStatus(Int32 status)     at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)     at DevExpress.XtraEditors.Drawing.PictureEditPainter.DrawImageCore(ControlGraphicsInfoArgs info, PictureEditViewInfo vi, RectangleF screen, RectangleF source, Image image, Boolean prevImage)     at DevExpress.XtraEditors.Drawing.PictureEditPainter.DrawImage(ControlGraphicsInfoArgs info)     at DevExpress.XtraEditors.Drawing.PictureEditPainter.DrawContent(ControlGraphicsInfoArgs info)     at DevExpress.XtraEditors.Drawing.BaseControlPainter.Draw(ControlGraphicsInfoArgs info)     at DevExpress.XtraEditors.Drawing.BaseEditPainter.Draw(ControlGraphicsInfoArgs info)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DrawRowValueCellCore(CustomDrawRowValueCellEventArgs e, BaseEditPainter pb, BaseEditViewInfo bvi, BaseViewInfo vi)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DrawRowValueCell(RowValueInfo rv, BaseViewInfo vi, MultiEditorRowViewInfo meri, Int32&amp; sepIndex)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DrawRow(BaseRowViewInfo ri)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DrawRows(BaseViewInfo vi)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DoDrawCore(BaseViewInfo vi)     at DevExpress.XtraVerticalGrid.Painters.VGridPainter.DoDraw(DXPaintEventArgs e, BaseViewInfo vi)     at DevExpress.XtraVerticalGrid.VGridControlBase.OnPaint(PaintEventArgs e)     at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)     at System.Windows.Forms.Control.WmPaint(Message&amp; m)     at System.Windows.Forms.Control.WndProc(Message&amp; m)     at DevExpress.XtraEditors.Container.EditorContainer.WndProc(Message&amp; m)     at DevExpress.XtraVerticalGrid.VGridControlBase.WndProc(Message&amp; m)     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)  Source: System.Drawing  </p>
  
  <p>I did notice that when calling this line 'img = System.Drawing.Image.FromStream(ms)',  the ms.position does not get to the end/ not equal to the length of ms.length and that's when I get this error.  </p>
  
  <p>Adding a little more context.  The original imagine was a .jpeg of about 30kb, saved to a memorystream which was then converted to a string and encoded to base64.  I saved the string into a sql database of varchar(max).  I then retrieve that string from sql and load the string into a datatable as a string.  When required, I then retrieve the string from the datatable and call the above function.</p>
  
  <p>This is the code I use to convert the image, which _newValue is then saved to sql database as varchar(max)</p>
  
  <pre><code>Using ms As System.IO.MemoryStream = New System.IO.MemoryStream()                             CType(value, Image).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
         _newValue = Convert.ToBase64String(ms.ToArray)
  End Using
  </code></pre>
  
  <p>Again, it only happens once in awhile on the same imagine.  Would anyone have any ideas why this would happen on and off?
  Thanks</p>