How to deal with different form of input and output in one class

Hi everybody,

I want to build new class library where i need to make some calculation and the input of the calculation is in form bitmap image and return the output in form of value of number or characters. Then, I want to call the output from mainform.cs.

The problem is, i couldn't return the output because it is not same with the type of the input. I found that the cause of error is because of the type of parameter in the constructor is different with the return type. Here is example of my code:

public ScanFirstStage(Bitmap image, string resultScan)
{
...
...
...
return resultScan
}
I think there are something error regarding the parameter but i don't know what to do. Could any body help me pls.. Pls ask me if the question is not clear.





Comments

  • : Hi everybody,
    :
    : I want to build new class library where i need to make some calculation and the input of the calculation is in form bitmap image and return the output in form of value of number or characters. Then, I want to call the output from mainform.cs.
    :
    : The problem is, i couldn't return the output because it is not same with the type of the input. I found that the cause of error is because of the type of parameter in the constructor is different with the return type. Here is example of my code:
    :
    : public ScanFirstStage(Bitmap image, string resultScan)
    : {
    : ...
    : ...
    : ...
    : return resultScan
    : }
    : I think there are something error regarding the parameter but i don't know what to do. Could any body help me pls.. Pls ask me if the question is not clear.
    :
    :
    :
    :
    :
    :

    what is the error you get? can you paste that?
    public string ScanFirstState(Bitmap x, string y)
    {...
    return y;
    } should not give any errors unless you are doing something funny elsewhere. give us more details as to what the function looks like.
  • Hi,

    Thanks for your respond.
    This is my class library that i build -->
    -----------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Text;


    namespace AForge.Imaging.Filters
    {
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using AForge.Math;
    using AForge.Imaging;

    public class ScanFirstStage
    {

    private int pixels;
    //private string resultScan;


    //Get result scanning
    public string Scan
    {
    get { return resultScan; }
    }

    //constructors
    public ScanFirstStage(Bitmap image)
    {

    }

    public string ScanFirstStage (Bitmap image, string resultScan)
    {

    // get image size
    int width = image.Width;
    int height = image.Height;

    pixels = width * height;
    // lock bitmap data
    BitmapData imgData = image.LockBits(
    new Rectangle(0, 0, width, height),
    ImageLockMode.ReadOnly,
    PixelFormat.Format64bppPArgb);

    int srcStride = imgData.Stride;
    int srcOffset = srcStride - width;
    string scan;

    // do the job
    unsafe

    {
    byte* p = (byte*)imgData.Scan0.ToPointer();
    int i = 0;
    string resultScan;


    for (int y = 0; y < height; y++)
    {
    for (int x = 0; x < width; x++)
    {

    if (*p != 0)
    {
    i++;
    }
    ++p;
    }

    p += srcOffset;

    }

    if (i >= 10)

    resultScan = "PASS";

    else
    resultScan = "FAIL";

    }

    // unlock image data
    image.UnlockBits(imgData);


    return resultScan;
    }

    }
    }

    -----------------------------------------------------------------------

    Then I called the clas from mainform.cs -->

    -----------------------------------------------------------------------

    System.Drawing.Bitmap image3 = (Bitmap)Bitmap.FromFile("ResultSubtract.Jpeg");
    // create filter for extraction
    AForge.Imaging.Filters.ScanFirstStage filter3 = new AForge.Imaging.Filters.ScanFirstStage(image3);
    //apply filter for extraction
    string scanning = filter3.resultScan;
    string sign = (string)scanning;
    objectCount.Text = sign.ToString();
    -----------------------------------------------------------------------

    The error is -->

    'ScanFirstStage': member names cannot be the same as their enclosing type


    I'm really appreciate if u can help me. Thanks.







    ------------------------------------------------------------
    : : Hi everybody,
    : :
    : : I want to build new class library where i need to make some calculation and the input of the calculation is in form bitmap image and return the output in form of value of number or characters. Then, I want to call the output from mainform.cs.
    : :
    : : The problem is, i couldn't return the output because it is not same with the type of the input. I found that the cause of error is because of the type of parameter in the constructor is different with the return type. Here is example of my code:
    : :
    : : public ScanFirstStage(Bitmap image, string resultScan)
    : : {
    : : ...
    : : ...
    : : ...
    : : return resultScan
    : : }
    : : I think there are something error regarding the parameter but i don't know what to do. Could any body help me pls.. Pls ask me if the question is not clear.
    : :
    : :
    : :
    : :
    : :
    : :
    :
    : what is the error you get? can you paste that?
    : public string ScanFirstState(Bitmap x, string y)
    : {...
    : return y;
    : } should not give any errors unless you are doing something funny elsewhere. give us more details as to what the function looks like.
    :

  • You have a string function called ScanFirstStage which is the same as your class name. The class name is reserved for the constructor, which gets called automatically and does not return a value. The solution is to change the name of your function from ScanFirstStage to something else.


    : Hi,
    :
    : Thanks for your respond.
    : This is my class library that i build -->
    : -----------------------------------------------------------------------
    :
    : using System;
    : using System.Collections.Generic;
    : using System.Text;
    :
    :
    : namespace AForge.Imaging.Filters
    : {
    : using System;
    : using System.Drawing;
    : using System.Drawing.Imaging;
    : using AForge.Math;
    : using AForge.Imaging;
    :
    : public class ScanFirstStage
    : {
    :
    : private int pixels;
    : //private string resultScan;
    :
    :
    : //Get result scanning
    : public string Scan
    : {
    : get { return resultScan; }
    : }
    :
    : //constructors
    : public ScanFirstStage(Bitmap image)
    : {
    :
    : }
    :
    : public string ScanFirstStage (Bitmap image, string resultScan)
    : {
    :
    : // get image size
    : int width = image.Width;
    : int height = image.Height;
    :
    : pixels = width * height;
    : // lock bitmap data
    : BitmapData imgData = image.LockBits(
    : new Rectangle(0, 0, width, height),
    : ImageLockMode.ReadOnly,
    : PixelFormat.Format64bppPArgb);
    :
    : int srcStride = imgData.Stride;
    : int srcOffset = srcStride - width;
    : string scan;
    :
    : // do the job
    : unsafe
    :
    : {
    : byte* p = (byte*)imgData.Scan0.ToPointer();
    : int i = 0;
    : string resultScan;
    :
    :
    : for (int y = 0; y < height; y++)
    : {
    : for (int x = 0; x < width; x++)
    : {
    :
    : if (*p != 0)
    : {
    : i++;
    : }
    : ++p;
    : }
    :
    : p += srcOffset;
    :
    : }
    :
    : if (i >= 10)
    :
    : resultScan = "PASS";
    :
    : else
    : resultScan = "FAIL";
    :
    : }
    :
    : // unlock image data
    : image.UnlockBits(imgData);
    :
    :
    : return resultScan;
    : }
    :
    : }
    : }
    :
    : -----------------------------------------------------------------------
    :
    : Then I called the clas from mainform.cs -->
    :
    : -----------------------------------------------------------------------
    :
    : System.Drawing.Bitmap image3 = (Bitmap)Bitmap.FromFile("ResultSubtract.Jpeg");
    : // create filter for extraction
    : AForge.Imaging.Filters.ScanFirstStage filter3 = new AForge.Imaging.Filters.ScanFirstStage(image3);
    : //apply filter for extraction
    : string scanning = filter3.resultScan;
    : string sign = (string)scanning;
    : objectCount.Text = sign.ToString();
    : -----------------------------------------------------------------------
    :
    : The error is -->
    :
    : 'ScanFirstStage': member names cannot be the same as their enclosing type
    :
    :
    : I'm really appreciate if u can help me. Thanks.
    :
    :
    :
    :
    :
    :
    :
    : ------------------------------------------------------------
    : : : Hi everybody,
    : : :
    : : : I want to build new class library where i need to make some calculation and the input of the calculation is in form bitmap image and return the output in form of value of number or characters. Then, I want to call the output from mainform.cs.
    : : :
    : : : The problem is, i couldn't return the output because it is not same with the type of the input. I found that the cause of error is because of the type of parameter in the constructor is different with the return type. Here is example of my code:
    : : :
    : : : public ScanFirstStage(Bitmap image, string resultScan)
    : : : {
    : : : ...
    : : : ...
    : : : ...
    : : : return resultScan
    : : : }
    : : : I think there are something error regarding the parameter but i don't know what to do. Could any body help me pls.. Pls ask me if the question is not clear.
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : : what is the error you get? can you paste that?
    : : public string ScanFirstState(Bitmap x, string y)
    : : {...
    : : return y;
    : : } should not give any errors unless you are doing something funny elsewhere. give us more details as to what the function looks like.
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories