|
yes , but Not For Rows , I don't think exist any property for Row to put a Text !
Thanks !
|
|
|
|
|
Then explain more clearly what you want.
System.Data.DataTable dt = new System.Data.DataTable() ;
for ( int col = 0 ; col < 10 ; col++ )
{
dt.Columns.Add ( new System.Data.DataColumn ( col.ToString() ) ) ;
}
for ( int row = 0 ; row < 10 ; row++ )
{
System.Data.DataRow dr = dt.NewRow() ;
for ( int col = 0 ; col < dt.Columns.Count ; col++ )
{
dr [ col ] = row * col ;
}
dt.Rows.Add ( dr ) ;
}
this.dataGridView1.DataSource = dt ;
for ( int row = 0 ; row < dt.Rows.Count ; row++ )
{
this.dataGridView1.Rows [ row ].HeaderCell.Value = row.ToString() ;
}
This gives me a DataGridView showing a multiplication table with the row headers showing the row number.
|
|
|
|
|
thanks for Ur Help , I wanted To give A Name for Each Row , that stored in a Combo Box !
|
|
|
|
|
How about you adding a DataGridViewColumn which would then hold the names you choose?
|
|
|
|
|
Hello all,
I am currently handling very large images, which are basically generated by stitching together many smaller images (e.g. panorama or photo mosaic software). In order to avoid out-of-memory exceptions (in memory are only "maps" of how to arrange the smaller images), I wrote some code saving these images line by line as bitmaps using BinaryWriter and LockBits. So far, so good.
The problem is now that I would like to save these images as Jpegs (or PNGs) as well. Since I am pretty new to c# I can only think of two ways for now:
1) Similar to the bitmap saving procedure. Generating some jpeg header and saving the big images line by line, compressing them somehow before. I have no idea how to perform the compression though.
2) Streaming the already saved bitmap into the memory and saving it as encoded jpeg.
Since the second approach seemed easier, I tried something like this:
FileStream fsr = new FileStream("input.bmp", FileMode.Open, FileAccess.Read);
FileStream fsw = new FileStream("output.jpg", FileMode.CreateNew, FileAccess.Write);
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);
Bitmap bmp = new Bitmap(fsr);
bmp.Save(fsw, GetEncoder(ImageFormat.Jpeg), encoderParameters);
bmp.Dispose();
The problem is now that the save-method tries to completely load the bitmap into memory first, causing an out-of-memory exception.
I would be more than happy for any suggestions on how to solve or circumvent this problem!
Cheers,
Max
Update: I now edited the code so that it saves bands of 8 lines as bmp. These bands I would now like to save to the same jpeg file - any ideas?
modified 24-Nov-11 8:04am.
|
|
|
|
|
|
Well, that's what it does. A third party encoder may be worth looking into, or you can roll your own. PNG is pretty easy to encode in a streaming way (the Deflate step obviously requires a buffer, but a constant-size small one). JPG of course can't exactly be encoded line-by-line, but block by block isn't any worse.
|
|
|
|
|
You can't get decent JPEG compression for images with insufficient height, the DCT step in the JPEG compression algorithm is using pixel blocks of 8 by 8 pixels. Any less will fail terribly.
Are you sure you are actually running out of memory? How many elementary images are there, and what is their size?
The reason I ask is GDI+ tends to be pretty confusing with its error messages, e.g. when Image.FromFile() says "out-of-memory" it really means "this is an image format I don't understand". See here[^].
|
|
|
|
|
@darkDercane: Yes, I would like to compress it. The problem is that I do not know how to do this chunk by chunk.
@harold aptroot: Do you by chance know of any example on how to encode (and save) a picture block-by-block?
@Luc Pattyn: It would be no problem to hand the compression algorithm blocks of 8x8 pixels, I chose to do it linewise for no real reason. Assuming that I deliver chunks of 8x8 or bigger, how can I encode these chunks into one JPG (or PNG) file?
And yes, I am pretty sure, I am really running out of memory. The filesize of each elementary image is about 10k px (e.g. 100x100), there could be sth like10 to 100k of them in the final image. I recently tested the program by saving the resulting image on hdd and got a 1.7 GB (32bpp) bmp monster image file. I do not plan to exceed the 32kpx limit of bmp though.
|
|
|
|
|
I have several small programs that scrap input and load it into a database. Since much of the code relies on external resources being ready, a lot of my code ends up being in try/catch blocks. Is there a lot of overhead associated with these? I have tried to consolidate interaction with external sites and db's so there are a minimal number.
Is there a better way to do this than having a block in each method?
Thx
Mark Jackson
|
|
|
|
|
|
IMO if a condition can be expected and tested for then it is not an exception and you shouldn't rely on exception handling.
No comment
|
|
|
|
|
Yes, but on some other hand somewhere... continually testing for a rare state wastes cycles.
|
|
|
|
|
Agreed. There is a difference between rare, unexpected conditions and common, expected conditions.
PIEBALDconsult wrote: some other hand somewhere
Did you forget where your other hand went? Or are you using someone else's hand?
No comment
|
|
|
|
|
IMO you should stay away from religious arguments.
By the time you're finished checking all the conditions, I could have the deleted the file that you're reading.
Bastard Programmer from Hell
|
|
|
|
|
This.
Writing "bullet proof" code that handles every case from day one, I've learned is a waste of your time and CPU cycles and does nothing but piss off your boss who is wondering why it is taking you so long. Write your first pass with general case error handling and add the obscure corner cases as you come across them in testing.
However, structuring your code with the intention of handling these corner cases down the road would behoove you.
What I mean by that is... well, one of the projects I'm working on is a project that my boss implemented 100%, and he is "from the street" and doesn't believe in structure and design, so there is SQL code sprinkled pretty much every where. Had he packaged all his SQL code into a single DAL, it would have been much easier to debug and expand. The project that I wrote 100% from scratch, I did exactly that... yeah, it didn't handle every corner case from day one, but as I found the cases, I only had to change 1 or 2 places.
I'm mentioning this because it sounds like you have your external access stuff sprinkled everywhere throughout the GUI .
|
|
|
|
|
Indeed, where it's appropriate, a simple check can often save time. Ultimately, as you progress, you end up building a handy set of utility methods that you can use, for instance here's a simplified version of a file create that you could use:
public static FileStream TryCreateFile(string fileToCreate)
{
string directoryName = Path.GetDirectoryName(fileToCreate);
if (!Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
return File.Create(fileToCreate);
}
modified 23-Nov-11 15:33pm.
|
|
|
|
|
How does that save time? Delete will check for the existence of the file a second time.
Edit: Or is that just a bad example?
"If the file to be deleted does not exist, no exception is thrown."
modified 23-Nov-11 15:20pm.
|
|
|
|
|
It was actually a bad example - I'll update it with the example I was actually thinking of.
|
|
|
|
|
I'm afraid this isn't your day; you failed at improving the example.
Directory.CreateDirectory() does nothing when the folder already exists, so there is no point checking first.
|
|
|
|
|
Actually, in this particular case, there is - the IL is slightly different internally, and it saves clock cycles on the test in CreateDirectory. That's the reason it's in. The important part is actually the second part - hence the point of the example.
|
|
|
|
|
Ah. I never looked at the IL, I was assuming they were smart enough to make the test inside CreateDirectory() as efficient as the one inside Exists() .
|
|
|
|
|
Why do I feel the need to go "Helloooooo. Microsoft."?
|
|
|
|
|
I don't know. Besides, I prefer How questions over Why questions any day.
|
|
|
|
|
Wouldn't be so handy if you'd use it to clear a folder. If you recently fetched the folders' contents, chances are that the files still exist.
Bastard Programmer from Hell
|
|
|
|