|
variables: filename
Properties, classes, methods... : FileName
I hate constructs like sFileName or bMyBool to also indicate the type and also gVariable or _variable to indicate global or class variables, but that might be personal.
V.
|
|
|
|
|
I personally prefer filename just as other people have stated, it is easy to read. Arguably it is becoming part of the language as a single word, I tend to think of filename as a more specific concept than name of a file that the version with the space implies. As an aside some dictionaries seem to agree .http://dictionary.reference.com/browse/filename[^].
FXCop disagrees and insists on fileName (see this blog post/[^]), and consistency are important. I'd rather agree with the framework and I assume MS uses FXCop's default rules .I can't find an example of fileName , but I'm 75% sure I've seen it somewhere... As a second point filename looks odd set aside filePath .
So the answer is for consistancy go for fileName , but filename isn't so bad that you shouldn't use it if you find it easier to read, the important thing is to stick to one version in your code.
|
|
|
|
|
Keith Barrow wrote: As a second point filename looks odd set aside filePath
That raises another question. I notice that sometimes an api uses filename to refer just to name of the file, other times to mean the file path. That can be confusing. I tend to adopt a convention of using path for full path and name for just the name.
But there is some MS class where in one method they use name to mean just the name and in another method to mean the full path!
Kevin
|
|
|
|
|
|
Hi,
you can use StyleCop for coding convention. there are some rules for naming in it.
thanks
-Amit.
|
|
|
|
|
There are so many criterias.If it is a public property , make it "FileName".If it is a private member make it "_fileName" n for local variable make it "fileName".There are naming standards of c#.Go and read it.Or else install SCA for VS and make all naming warnings as errors.It will give u a good idea. 
|
|
|
|
|
I mostly go for filename as it is often interpreted in various places as a single word, e.g., http://en.wikipedia.org/wiki/Filename[^]. Sometimes it depends on what code I'm integrating with. I try to be as consistent as possible in the given context.
Kevin
|
|
|
|
|
Hi I'm trying to push a double[,] array of pixel values from a greyscale buffer into a bitmap using lockbit using:
Bitmap bmp;
byte pixVal;
unsafe{
bmp = new Bitmap(Width,Height);
BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, Width, Height),
ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
byte* row;
for (int j = 0; j < Height; j++){
row = (byte*)bmpData.Scan0 + (j * bmpData.Stride);
for (int i = 0; i < Width; i++){
pixVal = (byte)(PixelScaleFactor *
_internalPixelArray[i, j] - PixelOffset));
row[i * PixelDepth] = pixVal;
row[i * PixelDepth + 1] = pixVal;
row[i * PixelDepth + 2] = pixVal;
}
}
bmp.UnlockBits(bmpData);
}
in which _internalPixelArray is a 1000x1000 array of doubles. The scale factor and pixelOffset have been calculated correctly.
When run I get an AccessViolationException when j = 991 and i = 918.
Could there be a reason for this?
Cheers,
|
|
|
|
|
Hi,
1. what are the actual dimensions of the bitmap?
2.
Ylno wrote: PixelFormat.Format24bppRgb
It would be cleaner to use bmp.PixelFormat
3. which is the exact line that throws the exception?
4. you should make local copies of Width and Height. As it is now, and assuming the code resides inside a Form class, resizing the Form while that code executes could result in havoc.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Hi Luc,
1) in this test 1000x1000 but in practice 1024x1024 or 2048x2048
2) using bmp.PixelFormat (see below)
3) the line with
row[i * PixelDepth] = pixVal; within the inner loop throws.
background: I'm parsing grayscale pixel data from an obscure image format used in electron-microscopy. Along with the pixel values I get the Width, Height and PixelDepth. The actual image has been acquired on expensive ccd equipment therefore pixels can be quite deep. I want to be able to display an array of greyscale pixel values (double[,] pixelValues) within a picture box. For this I see no other way than creating a Bitmap/Image in memory and displaying this. It appears .NET does not support deep greyscale therefore I thought for the purposes of display only I could rescale the pixelArray from double[,] to byte[,] and assign each of the RGB channels for a given pixel to the byte value from the temporary byte[,] array.
Towards this end my code creates a byte-buffer vector in which I encode a Bitmap. First I write the header in which I define the pixelDepth to be 32. Previously I thought I could use ARGB 32bbp format and push the byte pixelValue in R, G and B a constant in the A channel. This worked:
....... code to write the bitmap header here ........
for (int j = Height - 1; j >= 0; j--)
{
for (int i = 0; i < Width; i++)
{
pixVal = (byte)(PixelScaleFactor * (_internalPixelArray[i, j] - PixelOffset));
buffer.writeByte(pixVal);
buffer.writeByte(pixVal);
buffer.writeByte(pixVal);
buffer.writeByte(0);
}
}
I then use the bitmap encoded byte[] buffer to create a memory stream from which I create an image by:
Image.FromStream(new System.IO.MemoryStream(imageData))
This works but takes 200ms to encode and display an image. To make things
quicker I thought I might be able to by encoding a buffer with a bitmap header as above and not assign the pixel values immediately but instead create a Bitmap using the memory stream method which results in an images with all pixels as zero. Then once I have the Bitmap object used Lockbits to set the pixels. I got to point and got an AccessViolation. I thought my buffer might not be long enough so I backed up a bit and started testing with the code I posted. i.e. create a simple bitmap using Bitmap(width, height) constructor and specify the pixelDepth with the Lockbits method. This way I thought I would be allocated a memory block of the correct size.
I simply want to display a greyscale array of pixel-values I don't care about the loss of precision since I keep the actual pixelArray separately for image-processing operations.
by the way your company looks interesting.
cheers
|
|
|
|
|
Ylno wrote: 2) using bmp.PixelFormat (see below) I don't see it!
5. We haven't discussed PixelDepth yet. Is it 3? or 24? or ...?
6. I have no idea why it would work well for most of the image, and then throw for i=918; I see no reasonable combination of parameter values that would work well till row 918 and then fail.
7. you don't need to construct a bitmap header, you can let .NET do that for you as Bitmap has a constructor that takes a pixel array pointer (raw pixels, no metadata). Check MSDN, and make sure you read the remarks.
8. FWIW: I would never store image data in a 2D array, a linear array is what I prefer.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Thanks again for getting back to me on this subject.
Luc Pattyn wrote: I don't see it!
sorry, I simply meant my discussion about having pixels stored in a double[,] array but not really caring with what pixel-depth the bitmap is since is it is only for display purposes not calculation.
5. I guess "see above"
6. Same here. Other than GDI+ not fully supporting 16bpp. There is very little on the net regarding using 16bpp greyscale Bitmaps and what there is is old and contradictory.
7. I went with your suggestion here however I couldn't get things to work using PixelFormat.Format16bppGrayScale. Instead I went with 24bppRGB instead. For the benefit of others see code below.
8. yes, I was aware of this (once) but could you remind me of the benefits? My reasons for using 2D are:
8.1 - the dimensions are carried with the data in array.GetLength(int dimension). The vector approach requires lacks this.
8.2 - the array is analogous to the raster image and therefore conceptually simpler.
8.3 - this is my first 'real' stab at writing an heavy image processing application.
Aren't the 2D and 1D arrays arranged the same in memory?
Thanks again for your help. Pushed me towards a solution.
and finally here's what I came up with:
int width = 1000;
int height = 1000;
byte[] pixelVector = new byte[width * height * 3];
for (int loop = 0; loop < (width * height ); loop+=3)
{
pixelVector[loop] = (byte)((loop * 256) / (width * height ));
pixelVector[loop + 1] = (byte)((loop * 256) / (width * height ));
pixelVector[loop + 2] = (byte)((loop * 256) / (width * height ));
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);
unsafe
{
byte* row = (byte*)bmpData.Scan0;
for (int loop = 0; loop < (pixelVector.Length*3); loop+=3){
row[loop] = pixelVector[loop/3];
row[loop + 1] = pixelVector[loop/3 ];
row[loop + 2] = pixelVector[loop/3 ];
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image = bmp;
modified 26-Jan-12 12:41pm.
|
|
|
|
|
Hi again,
5. Now I see it.
6. Yes, sthe formats aren't documented well, and the RGB approach is justified.
7. The suggestion actually was and is to fill an array with RGB bytes, then use the constructor rather than your loops, should go faster. Drawback is you have to keep the array alive, or make another copy of the bitmap.
8. Having only one pointer or one index ("loop") typically is simpler and faster than having two indexes.
9. your code as shown wouldn't work, why are you storing bytes thrice, the last two bytes will throw an IndexOutOfBoundsException; storing everything thrice isn't useful if you have an explicit copy loop anyway, it only makes sense when using the IntPtr-based constructor.
10. I'd like to know what performance you are getting when it works, I recall you used to have 200msec (for 1000*1000?).
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Hi Luc,
You spotted the mistake! Was just making sure you were paying attention. There was a factor of 3 missing from my display-array [width*height*3] and the increment on the loop is 3 not 1 (loop+=3 not loop++).
I'm filling the pixels thrice to have RGB values each the same. This gives me a greyscale and also some flexibility in that I can drop values from one of the channels and achieve colour a colour overlay effect with the same image.
With the code above using a 1000x1000 array input array ( i.e. a (1000x1000)x3 display array) I get 19ms total runtime for creating the display array, making the pixel assignments and displaying in a picture box! Nice.
Cheers for your help.
|
|
|
|
|
hello,
i need a help, can we replace the controls dynamically(example: replace radio button by textbox when some event has occurred), if yes then please help me in this
thank you
theanil
|
|
|
|
|
As you haven't specified what technology you are using (e.g. WinForms), I'm going to have to be fairly general here.
Yes you can. You would need to remove the controls you don't want from the parents control collection (you have to iterate over this using a for loop as you are removing items which you can't do inside a foreach if it directly affects the item being iterated). NOTE: Don't forget to dereference the eventhandlers.
Once you have removed them, add in your new controls taking care to set any relevant properties such as location, etc.
|
|
|
|
|
thank you,
but i tried that way,
i need to toggle between the controls and as the answer you said, deleting the controls every time and adding new one is time consuming, is there any alternate way to do this.
theanil
|
|
|
|
|
Rather than delete them, change their Visibility. The downside is that you will consume more memory leaving that much open.
|
|
|
|
|
i can try that thing, i am working on IEEE paper so i have to check for both time and memory.
theanil
|
|
|
|
|
Well, yes you can, but why would you ? Particurlarly in this case: it's hard for me to imagine a scenario in which a RadioButton (usually used in groups where the function desired is to select one option from many) replaces a TextBox, or, the reverse.
The second thought ... which I see Pete O'Hanlon has already explained, is to implement both controls, and "swap" them by changing their visibility.
In the case where both "alternate" controls expose the same Events (with the exact same type of EventArgs parameter), you could have, for example, a RadioButton and a TextBox use the same EventHandler for Click, although I think that, too is "dubious" practice: better, imho, they each have their own Click handler, and then call a common method if there's any code that both Click events need to use.
So, I suggest you re-consider your design here.
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
|
|
|
|
|
but the tables will created on runtime....
|
|
|
|
|
OK, I've read that statement and I don't really understand what you are after. Are you trying to create a database table at runtime, or are you trying to create an HTML table? What have you actually done so far?
|
|
|
|
|
Pete is right - that makes no sense.
You have to remember that we can't see your PC, or read your mind. All we have to work with is what you have told us, and so far, that is not a lot. There are so many different meanings of "Table" within computing, that we cannot tell which one you mean. The same applies for "Generate" - you need to specify clearly exactly what you are trying to achieve, and ideally how far you have got so far.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Nice requirements !
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
for (int i=1; i<10; i++) {
outp("table of "+i);
for(int j=1; j<10; j++) {
int k=j*i;
outp(" "+j+" * "+i+" = "+k);
}
outp("");
}
is runtime
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|