Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
L

lexx_zone

@lexx_zone
About
Posts
7
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Image Brightness and Contrast change together
    L lexx_zone

    Guys, I need help. Sorry for my English now,my brain just refused to work. I have an Image in PictureBox and have some filters to its process: contrast and brightness. Two trackbars controls filters changing values. When trackBar1_ValueChanged or trackBar2_ValueChanged events raises, function ApplyFilter() starts to work in different thread. When I using the brightness trackbar it changes the brightness of basic image. When I using the contrast trackbar it changes the contrast of image, But I don't know how to change the brightness and contrast together and show it in pictureBox component. For example I want to increase a brightness of an image. After that I want to increase a contrast but not of basic image, and what has turned out at brightness increase. After that I want to decrease a brightness to its basic level or lower. I don't know How to explain it clearly... If anybody have Vista you can see the same example in Vista PhotoGallery fix component. There are a lot of filters which you can apply to your image and change it back as you need. Here is a logic of my code...

    Bitmap previewimage = null;
    int brightness_value = 0;
    int contrast_value = 0;

    public PicPreviewForm(string filename)
    {
    previewimage = new Bitmap(Image.FromFile(filename));
    pictureBox1.Image = previewimage;
    }
    public void ApplyFilter()
    {
    Bitmap bit;
    bit = new Bitmap(previewimage);

    if(brightness had been changed)
    {
    BrightnessFilter(bit, brightness_value);
    }
    If(contrast had been changed)
    {
    ContrastFilter(bit, contrast_value);
    }
    PictureBox.Image = bit;

    }

    I could apply all filters every time when I changing some trackbar but it really decrease program performance..

    C# help tutorial graphics performance

  • Image Brightness
    L lexx_zone

    I've found one cool algorithm for brightness and contrast's change.

    public static bool Brightness(Bitmap b, int nBrightness)
    {
    if (nBrightness < -255 || nBrightness > 255)
    return false;

    		// GDI+ still lies to us - the return format is BGR, NOT RGB.
    		BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
    
    		int stride = bmData.Stride;
    		System.IntPtr Scan0 = bmData.Scan0;
    
    		int nVal = 0;
    
    		unsafe
    		{
    			byte \* p = (byte \*)(void \*)Scan0;
    
    			int nOffset = stride - b.Width\*3;
    			int nWidth = b.Width \* 3;
    
    			for(int y=0;y<b.Height;++y)
    			{
    				for(int x=0; x < nWidth; ++x )
    				{
    					nVal = (int) (p\[0\] + nBrightness);
    	
    					if (nVal < 0) nVal = 0;
    					if (nVal > 255) nVal = 255;
    
    					p\[0\] = (byte)nVal;
    
    					++p;
    				}
    				p += nOffset;
    			}
    		}
    
    		b.UnlockBits(bmData);
    
    		return true;
    	}
    
    	public static bool Contrast(Bitmap b, sbyte nContrast)
    	{
    		if (nContrast < -100) return false;
    		if (nContrast >  100) return false;
    
    		double pixel = 0, contrast = (100.0+nContrast)/100.0;
    
    		contrast \*= contrast;
    
    		int red, green, blue;
    		
    		// GDI+ still lies to us - the return format is BGR, NOT RGB.
    		BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
    
    		int stride = bmData.Stride;
    		System.IntPtr Scan0 = bmData.Scan0;
    
    		unsafe
    		{
    			byte \* p = (byte \*)(void \*)Scan0;
    
    			int nOffset = stride - b.Width\*3;
    
    			for(int y=0;y<b.Height;++y)
    			{
    				for(int x=0; x < b.Width; ++x )
    				{
    					blue = p\[0\];
    					green = p\[1\];
    					red = p\[2\];
    			
    					pixel = red/255.0;
    					pixel -= 0.5;
    					pixel \*= contrast;
    					pixel += 0.5;
    					pixel \*= 255;
    					if (pixel < 0) pixel = 0;
    					if (pixel > 255) pixel = 255;
    					p\[2\] = (byte) pixel;
    
    					pixel = green/255.0;
    					pixel -= 0.5;
    					pixel \*= contrast;
    					pixel += 0.5;
    					pixel \*= 255;
    					if (pixel < 0) pixel = 0;
    					if (pixel > 255) pixel = 255;
    					p\[1\] = (byte) pixel;
    
    					pixel = blue/255.0;
    					pixel -= 0.5;
    					pixel \*= contrast;
    					pixel += 0.5;
    					pixel \*= 255;
    					if (pixel < 0) pixel = 0;
    					if (pixel > 255) pixel = 255;
    					p\[0\] = (byte) pixel;					
    
    					p += 3;
    				}
    				p += nOffset;
    			}
    		}
    
    		b.UnlockBits(bmData);
    
    		return true;
    	}
    
    C# adobe performance help tutorial question

  • Image Brightness
    L lexx_zone

    Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

    C# adobe performance help tutorial question

  • Image (Bitmap) Brightness/Contrast
    L lexx_zone

    Guys, I thought about your decisions already to use thumbnails instead of main image. I actually tried to work with small images, but the size of image at which i got accepting filter performance was too small. I have to use an image cropping tool too and that is the main cause why I don't want to use small images. Maybe somebody knows some third party filters with good performance or how this functions realized in Photoshop or Vista? I really don't know how to use exposure features for large images. Maybe it can be possible to involve some graphic card possibility or something else...

    C# adobe performance help graphics tutorial

  • Image (Bitmap) Brightness/Contrast
    L lexx_zone

    Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

    C# adobe performance help graphics tutorial

  • How to get DiskDrive model if I know the Drive letter
    L lexx_zone

    Thank you very much for your examples. It was really helpful to me. I combined and modified your solutions and wrote this code:

       string VolumeName = "C:";
            ManagementScope scope = new ManagementScope(@"\\root\\cimv2");
            ObjectQuery query = new ObjectQuery("ASSOCIATORS OF {Win32\_LogicalDisk.DeviceID=\\"" + VolumeName + "\\"} where assocclass=Win32\_LogicalDiskToPartition");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection drives = searcher.Get();
            foreach (ManagementObject current in drives)
            {
                scope = new ManagementScope(@"\\root\\cimv2");
                query = new ObjectQuery("ASSOCIATORS OF {Win32\_DiskPartition.DeviceID=\\"" + current\["DeviceID"\].ToString() + "\\"} where assocclass=Win32\_DiskDriveToDiskPartition");
                searcher = new ManagementObjectSearcher(scope, query);
                drives = searcher.Get();
                foreach (ManagementObject current2 in drives)
                {
                    MessageBox.Show(current2\["model"\].ToString());
                }
            }
    
    C# question help tutorial

  • How to get DiskDrive model if I know the Drive letter
    L lexx_zone

    Guys, I need help. I know the volume letter. How can I get a model of physical disk drive which consists a volume with a known to me name? I think, I have to use WMI, maybe Win32_DiskDrive, but how can I compare logical disk with physical disk?

    C# question help tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups