C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to deal with different form of input and output in one class Posted by labby on 5 Sept 2006 at 11:16 PM
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.





Report
Re: How to deal with different form of input and output in one class Posted by creeshna on 6 Sept 2006 at 1:49 PM
: 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.
Report
Re: How to deal with different form of input and output in one class Posted by labby on 6 Sept 2006 at 10:21 PM
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.
:

Report
Re: How to deal with different form of input and output in one class Posted by iwilld0it on 7 Sept 2006 at 6:07 AM
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.
: :
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.