Click here to Skip to main content
15,883,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am converting .raw image into bmp and then displaying on image control in wpf. My UI is in WPF. I am also saving the bmp image in png or jpeg format. Now the challenge is correcting the bmp image using brightness and contrast. So is there any solution in C# or openCV or Aforge?

What I have tried:

public void DisplayImage16(string fileName)
       {

           try
           {

               BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open));
               ushort pixShort;
               int i;
               long iTotalSize = br.BaseStream.Length;
               int iNumberOfPixels = (int)(iTotalSize / 2);

               // Get the dimensions of the image from the user
               ID = new ImageDimentions(iNumberOfPixels);
               if (ID.ShowDialog() == true)
               {
                   width = Convert.ToInt32(ID.tbWidth.Text);
                   height = Convert.ToInt32(ID.tbHeight.Text);
                   canvas.Width = width;
                   canvas.Height = height;
                   img.Width = width;
                   img.Height = height;
                   pix16 = new ushort[iNumberOfPixels];

                   for (i = 0; i < iNumberOfPixels; ++i)
                   {
                       pixShort = (ushort)(br.ReadUInt16());
                       pix16[i] = pixShort ;

                   }
                   br.Close();

                   int bitsPerPixel = 16;
                   stride = (width * bitsPerPixel + 7) / 8;

                   // Single step creation of the image
                   bmps = BitmapSource.Create(width, height, 96, 96, PixelFormats.Gray16, null,
                       pix16, stride);
                   img.Source = bmps;
                   btnSavejpg.IsEnabled = true;
                   btnSavePng.IsEnabled = true;
               }
               else
               {
                   br.Close();
               }

           }
           catch (Exception e)
           {
               MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

           }
       }
Posted
Updated 20-Aug-21 0:25am
Comments
BillWoodruff 20-Aug-21 7:29am    
A little searching here on CP will get you relevant articles.

1 solution

 
Share this answer
 
Comments
BillWoodruff 20-Aug-21 7:27am    
+5 An act pf kindness on your part :)

I keep wondering if any of the question-posters here even bother to look at the list of links to relevant articles that CP displays on page right.
Richard MacCutchan 20-Aug-21 8:01am    
Maybe it is a generational thing, but it does seem to be all too common these days.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900