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]
|
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)?
|
Use a ColorMatrix. It will be almost instant.
|
|
Maurits
Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
|
|
|
| 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();
|
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
|
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
|
|
|
Pretty interesting program I must say.
|
I have made one that does change in contrast, I'll put it up in a little while.
Angus Higgins
Change Brightness
[Save]
|
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.
|
| 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
|
|
|