using Microsoft.VisualBasic.Compatibility.VB6;
internal class VB6CompatibilityConverter
public static stdole.IPictureDisp ImageToPictureDisp(Image image)
return (stdole.IPictureDisp)Support.ImageToIPictureDisp(image);
public static Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
return Support.IPictureDispToImage(pictureDisp);
}
internal class PictureDispConverter
public static stdole.IPictureDisp BitmapToPictureDisp(Bitmap bitmap)
return new PictureDispImpl(bitmap);
public static Image PictureDispToBitmap(stdole.IPictureDisp pictureDisp)
// TODO
return null;
internal class PictureDispImpl : stdole.IPictureDisp, stdole.IPicture
#region Init
[DllImport("gdi32.dll")]
static extern void DeleteObject(IntPtr handle);
private Bitmap _image;
private IntPtr _handle;
public PictureDispImpl(Bitmap image)
_image = image;
~PictureDispImpl()
if (_handle != IntPtr.Zero)
DeleteObject(_handle);
#endregion
#region IPictureDisp Members
public int Width
get { return _image.Width; }
public int Height
get { return _image.Height; }
public short Type
get { return 1; }
public int Handle
if (_handle == IntPtr.Zero)
_handle = _image.GetHbitmap();
return _handle.ToInt32();
public int hPal
get { return 0; }
set { }
public void Render(
int hdc, int x, int y, int cx, int cy, int xSrc, int ySrc, int cxSrc, int cySrc, IntPtr prcWBounds)
Graphics graphics = Graphics.FromHdc(new IntPtr(hdc));
graphics.DrawImage(
_image, new Rectangle(x, y, cx, cy), xSrc, ySrc, cxSrc, cySrc, GraphicsUnit.Pixel);
#endregion
#region IPicture Members
public int Attributes
get { return 0; }
public int CurDC
get { return 0; }
public bool KeepOriginalFormat
get { return false; }
set { }
public void PictureChanged()
public void SaveAsFile(IntPtr pstm, bool fSaveMemCopy, out int pcbSize)
pcbSize = 0;
public void SelectPicture(int hdcIn, out int phdcOut, out int phbmpOut)
phdcOut = 0;
phbmpOut = 0;