Invert Colors

Angus

Angus Higgins
This program is one that inverts the colors of a picture. I was hoping that someone could tell me a way of making this program work faster, as currently it is somewhat lacking in speed.<BR><BR>Thanks in advance<BR><BR>Angus Higgins
Posted by Angus // Wed, Aug 3, 2005 8:19 AM

This program is one that inverts the colors of a picture. I was hoping that someone could tell me a way of making this program work faster, as currently it is somewhat lacking in speed.

Thanks in advance

Angus Higgins
[Save]
  Yargnits
 
 
  Tue, Aug 2 2005 2:17 PM
Instead of

                        int R = UserImage.GetPixel(WidthPixels, HeightPixels).R;
                        int G = UserImage.GetPixel(WidthPixels, HeightPixels).G;
                        int B = UserImage.GetPixel(WidthPixels, HeightPixels).B;
                        UserImage.SetPixel(WidthPixels, HeightPixels, Color.FromArgb(255 - R, 255 - G, 255 - B));

couldn't you do
                        int invert = 0xFFFFFF;
                        UserImage.SetPixel(WidthPixels, HeightPixels, Color.FromArgb(UserImage.GetPixel(WidthPixels, HeightPixels).ToArgb ^ invert);

(or some other more efficient way of XORing every pixel in the picture)?


  John Galt
 
 
  Tue, Aug 2 2005 3:05 PM
Use a ColorMatrix. It will be almost instant.


  Maurits
  Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
 
  Tue, Aug 2 2005 3:33 PM
John Galt wrote:
Use a ColorMatrix. It will be almost instant.


ColorMatrix example from Bob Powell
Image img=Image.FromFile(<filename>);
Bitmap copy=new Bitmap(img.Width,img.Height);
ImageAttributes ia = new ImageAttributes();
ColorMatrix cm=new ColorMatrix();
cm.Matrix00=-1;
cm.Matrix11=-1;
cm.Matrix22=-1;
ia.SetColorMatrix(cm);
Graphics g=Graphics.FromImage(copy);
g.DrawImage(img,new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
g.Dispose();
img.Dispose();


  Angus
  Angus Higgins
 
  Wed, Aug 3 2005 7:49 AM
I have made a program that uses ColorMatrix class, but it uses System.Drawing.Graphics, so it draws an image onto a component, is there a way to use System.Drawing.Graphics to draw onto a blank bitmap, or just implement the ColorMatrix class without System.Drawing.Graphics?

Thanks in advance

Angus Higgins

  Angus
  Angus Higgins
 
  Wed, Aug 3 2005 8:24 AM
Thanks for the tips you guys, I have finally made it go at a speed that is acceptable, I have updated the .zip file so you can have a look for yourself, the mostI have had to wait was about 1 second, and that was when I inverted a gargantuan image of dimensions 5120 by 1024 pixels, if you want to see it, it is here.

Thanks for all your help, I may extend the program to offer grayscale, and brightness changing.

Angus Higgins

  Manip
  Be sure brain is in gear before engaging mouth
 
  Fri, Aug 5 2005 9:16 PM
Pretty interesting program I must say.

  Angus
  Angus Higgins
 
  Sat, Aug 6 2005 2:29 PM
I have made one that does change in contrast, I'll put it up in a little while.

Angus Higgins

Change Brightness




[Save]

  Loadsgood
  What is your answer?
 
  Tue, Aug 9 2005 1:00 AM
Can anyone convert his app into a .NET 1.1 app? I'm too lazy to install .NET 2.0 and I'd love to be able to use it.



Make the Change Brightness program have its own thread.
Loadsgood.

  Angus
  Angus Higgins
 
  Tue, Aug 9 2005 5:34 AM
Loadsgood wrote:
Make the Change Brightness program have its own thread.
Loadsgood.


OK, I'll add a new thread for change brightness.

Thanks

Angus Higgins