Tyler Miles

Tyler Miles

  • NA
  • 11
  • 1.1k

I can't pass parameter to method.

Aug 3 2019 9:29 AM
Hi, i am new with C# and OOP.
I created a method (it blurs an image) . And it works well.  I will create another method. And i need blurred image as input parameter. But i don't know how to do this? (I tried something. But none of them didn't work) 
Here is my try:
  1. private void sliderKernel_MouseUp(object sender, MouseEventArgs e)  
  2. {  
  3.  Filtreler f1 = new Filtreler(); //Filtreler is name of my class  
  4.  f1.Img = new Bitmap(pBox_SOURCE.Image);  
  5.  int kernelsize = sliderKernel.Value;  
  6.  Bitmap MeanImg = f1.meanfilter(kernelsize, f1.Img); //this method works well.now, i would like to use MeanImg  
  7.  pBox_PROCESSED.Image = MeanImg;  
  8.  f1.CorrectShade(f1.Img, MeanImg); //But i can't. All the pixel values are come as zero  
  9.  pBoxShadeCorrection.Image = MeanImg;    
  10. }  
 
  1. public Bitmap Img { getset; } //my Properties   
  2. public Color PixelValue { getset; }   
 
  1. public Bitmap meanfilter(int kernelsize, Bitmap InputImage)  
  2. {   
  3.     Bitmap CikisResmi = new Bitmap(GirisResmi.Width, GirisResmi.Height);  
  4.    //blurring operations 
  5.    return CikisResmi;  
  6. //I blurred the image. No problem with this method  
  7. }  
 
  1. public Bitmap CorrectShade(Bitmap InputImage,Bitmap BlurredImage)  
  2. {  
  3.     Color PixelVauleBlurred;  
  4.     int divR,x,y;  
  5.     int ImgWidth = InputImage.Width;  
  6.     int ImgHeight = InputImage.Height;  
  7.     for (x = 0; x < ImgWidth; x++)  
  8.     {  
  9.         for (y = 0; y < ImgHeight; y++)  
  10.         {  
  11.             PixelVauleBlurred = BlurredImage.GetPixel(x, y);  
  12.             PixelValue = InputImage.GetPixel(x, y);  
  13.             divR = Convert.ToInt16(1f*OkunanRenk.R / PixelVauleBlurred.R); //Error line            //Error message:System.DivideByZeroException: 'Attempted to divide by zero.'
  14.             BlurredImage.SetPixel(x, y, Color.FromArgb(divR, divR, divR));  
  15.         }  
  16.     }  
  17.     return BlurredImage;  
  18. }  

Answers (7)