Metagen
2009-06-01 17:06:47
Yay for c#
My form obviously doesn't work properly, because i really dont care. But try turning on follow cursor and putting it over rs :o i had lots of fun.
I attatched an exe
Feechurs incl00d:
1. Zoom in and out to rediculous numbers
2. invert colors.
3. turn on and off R G and/or B
4. you can make a magnifier portal :o (zoom out and turn on follow cursor, then put it over itself)


Below is the only code of interest.
My form obviously doesn't work properly, because i really dont care. But try turning on follow cursor and putting it over rs :o i had lots of fun.
I attatched an exe
Feechurs incl00d:
1. Zoom in and out to rediculous numbers
2. invert colors.
3. turn on and off R G and/or B
4. you can make a magnifier portal :o (zoom out and turn on follow cursor, then put it over itself)


Below is the only code of interest.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication12
{
class BitManager
{
[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int x, int y);
[DllImport("gdi32.dll")]
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hbmp);
[DllImport("gdi32.dll")]
static extern IntPtr DeleteObject(IntPtr hbmp);
[DllImport("gdi32.dll")]
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, long SRCCOPY);
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
static extern Int32 DeleteDC(IntPtr hdc);
Bitmap theBMP;
const long SRCCOPY = 13369376;
public void LoadBits(int x1, int y1, int x2, int y2, double zoom, bool invert, bool r, bool g, bool b)
{
zoom = zoom + zoom;
int dx = (x2 - x1);
int dy = (y2 - y1);
int cx = (x2 + x1) / 2;
int cy = (y2 + y1) / 2;
x1 = cx - ((int)(dx / zoom));
x2 = cx + ((int)(dx / zoom));
y1 = cy - ((int)(dy / zoom));
y2 = cy + ((int)(dy / zoom));
IntPtr HWND = GetDesktopWindow();
IntPtr DC = GetDC(HWND);
IntPtr myDC = CreateCompatibleDC(DC);
IntPtr myBMP = CreateCompatibleBitmap(DC, x2 - x1, y2 - y1);
SelectObject(myDC, myBMP);
BitBlt(myDC, 0, 0, x2, y2, DC, x1, y1, SRCCOPY);
theBMP = null;
try
{
theBMP = Bitmap.FromHbitmap(myBMP);
}
catch (Exception)
{
}
finally
{
DeleteObject(myBMP);
ReleaseDC(HWND, DC);
DeleteDC(myDC);
}
if (invert ||! r || !g ||! b)
unsafe
{
BitmapData bitmapData = theBMP.LockBits(new Rectangle(0, 0, theBMP.Width, theBMP.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte* pos = (byte*)(bitmapData.Scan0.ToPointer());
for (int j = 0; j < bitmapData.Height; j++)
{
for (int i = 0; i < bitmapData.Width; i++)
{
if (!g)
pos[0] = 0;
if (!b)
pos[1] = 0;
if (!r)
pos[2] = 0;
if (invert)
{
// add modifier code here
pos[0] = (byte)(255 - pos[0]);
pos[1] = (byte)(255 - pos[1]);
pos[2] = (byte)(255 - pos[2]);
}
pos += 4;
}
}
theBMP.UnlockBits(bitmapData);
}
}
public void DrawToForm(System.Windows.Forms.Form form)
{
if (theBMP == null)
return;
using (Graphics g = Graphics.FromHwnd(form.Handle))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(theBMP, 0, 0, form.Width, form.Height);
}
theBMP.Dispose();
}
}
}