Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// After importing picture from file
for (int x = 0; x <= width; x++)
for (int y = 0; y <= height; y++)
// Use something like RGB(), but this -- as you know --
// is GDI, but make it a grey color or some other color
// and save it to crColor
SetPixel(hdc, x, y, crColor);
(C++.NET Version)
// Note: For some reason I got an error when I used BYTE
// so, I created TByte (TypeByte)
#define TByte unsigned char
void OnPaint(PaintEventArgs* e)
{
__super::OnPaint(e);
int width = this->Width;
int height = this->Height;
int color = Color::Black.ToArgb();
int stride;
int off;
TByte* bmpData = NULL;
Graphics* g = CreateGraphics();
Bitmap* bmp = new Bitmap(width, height, PixelFormat::Format32bppArgb);
BitmapData* dat = NULL;
Rectangle rect(0, 0, width, height);
dat = bmp->LockBits(rect, ImageLockMode::ReadWrite, PixelFormat::Format32bppArgb);
stride = dat->Stride;
off = stride - width * 4;
bmpData = (TByte*)dat->Scan0.ToPointer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
bmpData[3] = (TByte)((color >> 24) & 0xFF);
bmpData[2] = (TByte)((color >> 16) & 0xFF);
bmpData[1] = (TByte)((color >> 8) & 0xFF);
bmpData[0] = (TByte)((color) & 0xFF);
bmpData += 4;
}
bmpData += off;
}
bmp->UnlockBits(dat);
g->DrawImage(Image::FromHbitmap(bmp->GetHbitmap().ToPointer()), 0, 0);
g->Dispose();
}
------------------------
(C# Version [Faster])
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = this.CreateGraphics();
int width = this.Width;
int height = this.Height;
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData dat = null;
Rectangle r = new Rectangle(0, 0, width, height);
dat = bmp.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
int stride = dat.Stride;
int off = stride - width * 4;
byte* bmpData = (byte*)dat.Scan0.ToPointer();
int color = System.Drawing.Color.Black.ToArgb();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
bmpData[3] = (byte)((color >> 24) & 0xFF);
bmpData[2] = (byte)((color >> 16) & 0xFF);
bmpData[1] = (byte)((color >> 8) & 0xFF);
bmpData[0] = (byte)((color) & 0xFF);
bmpData += 4;
}
bmpData += off;
}
}
bmp.UnlockBits(dat);
g.DrawImage(Image.FromHbitmap(bmp.GetHbitmap()), 0, 0);
g.Dispose();
}