|
-
May 18th, 2002, 06:53 AM
#1
Thread Starter
Hyperactive Member
Inverting bitmap
Which method allows me to invert a bitmap object?
(Well, actually it will be sufficient to specify background color in bitmap constructor, if it is possible...)
-
May 18th, 2002, 07:38 AM
#2
Frenzied Member
Look in System.Drawing Namespace.
-
May 18th, 2002, 10:46 AM
#3
Here is some code I wrote to change a picture in a PictureBox around:
Code:
private void RotateRight()
{
//Code here rotates the picture right
Bitmap pic = new Bitmap(pbViewArea.Image);
pic.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
pbViewArea.Image = pic;
}
private void RotateLeft()
{
//Code here rotates the picture left
Bitmap pic = new Bitmap(pbViewArea.Image);
pic.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
pbViewArea.Image = pic;
}
private void FlipHorizontal()
{
//Code here flips the picture horizontally
Bitmap pic = new Bitmap(pbViewArea.Image);
pic.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX);
pbViewArea.Image = pic;
}
private void FlipVertical()
{
//Code here flips the picture vertically
Bitmap pic = new Bitmap(pbViewArea.Image);
pic.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
pbViewArea.Image = pic;
}
-
May 18th, 2002, 10:54 AM
#4
Thread Starter
Hyperactive Member
Well, thank you for reply; but I was thinking about color inverting - eg. changing black into white.
-
May 18th, 2002, 11:12 AM
#5
I just wrote this -- I think it works?
PHP Code:
private void button1_Click(object sender, System.EventArgs e)
{
Bitmap m = new Bitmap(pb1.Image);
Int32 ax = 0; Int32 ay = 0;
Color c = new Color();
int r,g , b ;
for (ax = 0; ax < m.Width; ax++)
{
for (ay = 0; ay < m.Height; ay++)
{
c = m.GetPixel(ax, ay);
r = Math.Abs(c.R - 255);
g = Math.Abs(c.G - 255);
b = Math.Abs(c.B - 255);
m.SetPixel(ax, ay, Color.FromArgb(r,g,b));
}
}
pb1.Image = m;
}
There's probably a faster way to do this :P
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|