Results 1 to 5 of 5

Thread: Inverting bitmap

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    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...)

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Look in System.Drawing Namespace.

  3. #3
    hellswraith
    Guest
    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;
    }

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    Well, thank you for reply; but I was thinking about color inverting - eg. changing black into white.

  5. #5
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    I just wrote this -- I think it works?
    PHP Code:
            private void button1_Click(object senderSystem.EventArgs e)
            {

                
    Bitmap m = new Bitmap(pb1.Image);
                
    Int32 ax 0Int32 ay 0;
                
    Color c = new Color();
                
    int r,;
                for (
    ax 0ax m.Widthax++)
                {
                    for (
    ay 0ay m.Heightay++)
                    {
                        
    m.GetPixel(axay);
                        
    Math.Abs(c.255);
                        
    Math.Abs(c.255);
                        
    Math.Abs(c.255);
                        
    m.SetPixel(axayColor.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
  •  



Click Here to Expand Forum to Full Width