[DllImport("gdi32.dll")]
static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest,
int nYOriginDest, int nWidthDest, int nHeightDest, IntPtr hdcSrc,
int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, uint dwRop);
The last argument uint dwRop from the signature above specifies a raster operation code defined in the header. A value from enum TernaryRasterOperations below can be used as the last argument to fake the defined value from this signature:
[DllImport("gdi32.dll")]
static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest,
int nYOriginDest, int nWidthDest, int nHeightDest, IntPtr hdcSrc,
int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, TernaryRasterOperations dwRop );
public enum TernaryRasterOperations
{
SRCCOPY = 0x00CC0020, /* dest = source*/
SRCPAINT = 0x00EE0086, /* dest = source OR dest*/
SRCAND = 0x008800C6, /* dest = source AND dest*/
SRCINVERT = 0x00660046, /* dest = source XOR dest*/
SRCERASE = 0x00440328, /* dest = source AND (NOT dest )*/
NOTSRCCOPY = 0x00330008, /* dest = (NOT source)*/
NOTSRCERASE = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */
MERGECOPY = 0x00C000CA, /* dest = (source AND pattern)*/
MERGEPAINT = 0x00BB0226, /* dest = (NOT source) OR dest*/
PATCOPY = 0x00F00021, /* dest = pattern*/
PATPAINT = 0x00FB0A09, /* dest = DPSnoo*/
PATINVERT = 0x005A0049, /* dest = pattern XOR dest*/
DSTINVERT = 0x00550009, /* dest = (NOT dest)*/
BLACKNESS = 0x00000042, /* dest = BLACK*/
WHITENESS = 0x00FF0062, /* dest = WHITE*/
};
StretchBlt can be used to create zoom functionality.
Please add some!
Performs a simple zoom on an Hbitmap (hbmp)
[DllImport("gdi32.dll")]
static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest,
int nYOriginDest, int nWidthDest, int nHeightDest, IntPtr hdcSrc,
int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
TernaryRasterOperations dwRop );
[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport("gdi32.dll", ExactSpelling=true, SetLastError=true)]
static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll")]
static extern bool SetStretchBltMode(IntPtr hdc, StretchMode iStretchMode);
public enum StretchMode
{
STRETCH_ANDSCANS =1,
STRETCH_ORSCANS =2,
STRETCH_DELETESCANS =3,
STRETCH_HALFTONE =4,
}
public enum TernaryRasterOperations
{
SRCCOPY = 0x00CC0020, /* dest = source*/
SRCPAINT = 0x00EE0086, /* dest = source OR dest*/
SRCAND = 0x008800C6, /* dest = source AND dest*/
SRCINVERT = 0x00660046, /* dest = source XOR dest*/
SRCERASE = 0x00440328, /* dest = source AND (NOT dest )*/
NOTSRCCOPY = 0x00330008, /* dest = (NOT source)*/
NOTSRCERASE = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */
MERGECOPY = 0x00C000CA, /* dest = (source AND pattern)*/
MERGEPAINT = 0x00BB0226, /* dest = (NOT source) OR dest*/
PATCOPY = 0x00F00021, /* dest = pattern*/
PATPAINT = 0x00FB0A09, /* dest = DPSnoo*/
PATINVERT = 0x005A0049, /* dest = pattern XOR dest*/
DSTINVERT = 0x00550009, /* dest = (NOT dest)*/
BLACKNESS = 0x00000042, /* dest = BLACK*/
WHITENESS = 0x00FF0062, /* dest = WHITE*/
};
protected override void OnPaint(PaintEventArgs e)
{
IntPtr pTarget = e.Graphics.GetHdc();
IntPtr pSource = CreateCompatibleDC(pTarget);
IntPtr pOrig = SelectObject(pSource, hbmp);
StretchBlt(pTarget, 0, 0, bmp.Width * 2, bmp.Height * 2,pSource,
0,0,bmp.Width, bmp.Height,TernaryRasterOperations.SRCCOPY);
IntPtr pNew = SelectObject(pSource, pOrig);
DeleteObject(pNew);
DeleteDC(pSource);
e.Graphics.ReleaseHdc(pTarget);
}
To Zoom out using StretchBlt use SetStretchBltMode before calling StretchBlt
protected override void OnPaint(PaintEventArgs e)
{
IntPtr pTarget = e.Graphics.GetHdc();
IntPtr pSource = CreateCompatibleDC(pTarget);
IntPtr pOrig = SelectObject(pSource, hbmp);
SetStretchBltMode(pTarget, StretchMode.STRETCH_DELETESCANS);
StretchBlt(pTarget, 0, 0, width/2, height/2,pSource, 0,0,bmp.Width,
bmp.Height,TernaryRasterOperations.SRCCOPY);
IntPtr pNew = SelectObject(pSource, pOrig);
DeleteObject(pNew);
DeleteDC(pSource);
e.Graphics.ReleaseHdc(pTarget);
}
Do you know one? Please contribute it!