|
That's what I meant, thanks.
I see
FILE *streamp = fopen(
and
fclose(streamt );
Is that just a typo?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Oh, I'm sorry, I copied another part of the algorithm that creates one of the files that are working.
this is the parte where he declarates the streamt:
Cmatrix correspondencias3;
correspondencias3.crea_matriz(W,H,4);
FILE *streamt = fopen("results/correspondencias3.txt", "w");
and this is the part that it uses to create the .txt:
for (y= 0; y<H ; y++)
{
int *current = &m_disparity.Pixel(0, y, 0);
for (x = 0; x < W; x++)
{
correspondencias3.asignar_filas(x,y,current[x]);
if (x==W-1)
fprintf(streamt,"%d,%d %d,%d;\n",correspondencias3.matrix[x][y][0],correspondencias3.matrix[x][y][1],correspondencias3.matrix[x][y][2],correspondencias3.matrix[x][y][3]);
else
fprintf(streamt,"%d,%d %d,%d; ",correspondencias3.matrix[x][y][0],correspondencias3.matrix[x][y][1],correspondencias3.matrix[x][y][2],correspondencias3.matrix[x][y][3]);
}
}
fclose(streamt);
the problem is with correspondencias3.txt, correspondencias1.txt and correspondencias2.txt are working perfect.
if this is not the problem, what could it be?
thanks again for your help! I really really appreciate it!
if you need more info, just tell me.
|
|
|
|
|
Some process is holding the file open.
The only thing I can think of is step through the code -
especially from the point the file is opened (fopen()) to
where it gets closed (fclose()).
Make sure there's no execution paths that bypass the fclose().
Also check the return value of fclose().
Make sure there's no typos since you're working with 3 similarly named
sets of objects.
Good luck
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well, I did it!
I didn't modify the file that was created by the C++ DLL. What I did was copying the file into another one.
In the C# I put this:
try
{
File.Copy(VariablesGlobales.path1 + "results\\correspondencias3.txt", VariablesGlobales.path1 + "results\\correspondencias4.txt");
}
catch
{
MessageBox.Show("No se pudo leer archivo de texto, favor haga click en Aceptar y espere un momento", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
string[] lines = System.IO.File.ReadAllLines(VariablesGlobales.path1 + "results\\correspondencias4.txt");
I did a new one, a new .txt. That new one was the one that I read and copy to the new array!
Thanks a lot for your help again!
|
|
|
|
|
Thanks,but as per my requirement,without copying the file,i have to access the file.Any solution?please...
Regards,
Kiruthika
|
|
|
|
|
From my experience, the static methods of the "File" class are very slow compared to streams. Maybe 100 times slower. If you have concurrent access to a file it is best to make the reads and writes as short as possible.
I recommend replacing File.ReadAllLines with:
using (StreamReader sr = new StreamReader(...))
{
lines = sr.ReadToEnd();
}
Keyboard not found. Press F1 to continue.
|
|
|
|
|
How do I release the resources for an image so I can rename or delete it.
Bitmap pic = new Bitmap(infile);
pictureBox1.Image = pic;
// A button is clicked to rename or delete the picture
// I have tried
pic=null;
pictureBox1.Image=null;
File.Move(inpic, outpic);
//I get ************** Exception Text **************
//System.IO.IOException: The process cannot access the file because it is
//being used by another process.
I have seen this issue dealt with before but have not been able to find where.
|
|
|
|
|
The problem is that the picture was never Disposed. There are also bugs in the framework, I find the best thing is to create the bitmap, make a copy, work with the copy, and call Dispose on the original object. Setting to null doesn't do much, although it can increase the time before GC collects it, there's no immediate effect on the object.
Christian Graus
Driven to the arms of OSX by Vista.
"Iam doing the browsing center project in vb.net using c# coding" - this is why I don't answer questions much anymore. Oh, and Microsoft doesn't want me to.
|
|
|
|
|
electriac wrote: How do I release the resources for an image so I can rename or delete it.
Dispose it!
pic.Dispose();
pic=null;
GDI+ keeps the image stream open until you dispose the image.
It's buried way deep in the documentation - like a one sentence
blurb in an overview somewhere.
You can work with a clone as well, like Christian mentioned.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark that did the trick!
|
|
|
|
|
Hey there, it was my post about a month ago you're talking about Glad you found the solution , One more problem is in the pictureBox control "when loading it with a bitmap", more details are on msdn website..
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Do you have a URL for that I was not able to find it with a search.
|
|
|
|
|
|
Muammar
Thanks for the link.
I am doing a rewrite of my media player which displays images associated with the MP3 files. Since the program also deletes, renames, and exports groups of files I have had some difficulty do to the problem of unreleased resources. I believe that with the help of all you "Code Project" people I have everything working now.
Thanks to all
Electriac
|
|
|
|
|
I am certain that there have been times that I've disposed of the image and it's still held onto the file, depending on how it was opened. But, yeah, as we both said, Dispose is the underlying solution that the OP was missing.
Christian Graus
Driven to the arms of OSX by Vista.
"Iam doing the browsing center project in vb.net using c# coding" - this is why I don't answer questions much anymore. Oh, and Microsoft doesn't want me to.
|
|
|
|
|
It seems that MS doesn't want anything help full, altruistic, or practical. Thanks for the help.
|
|
|
|
|
Christian Graus wrote: I am certain that there have been times that I've disposed of the image and it's still held onto the file
Yup - I've seen this. It seems to depend (to a certain extent) on how the image was opened in the first place.
|
|
|
|
|
Pete O'Hanlon wrote: It seems to depend (to a certain extent) on how the image was opened in the first place.
That makes sense. Disposing the Bitmap to make it release the file only works if it's actually the Bitmap that is holding on to the file.
The Bitmap should always be disposed, of course, even if it's not to release the file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yeah "Deja View" I know I have seen this issue before but after spending many hours with Google etc. to no avail I resorted to asking for help. Many thanks Code Project. I try not to ask questions unless I have exhausted all alternatives. Thanks for your help I now have greater insight into the issue than my simple problem required.
|
|
|
|
|
electriac wrote: I know I have seen this issue before but after spending many hours with Google etc
That's the spirit. BTW - don't think that Deja View referred to your problem. It's part of my sig.
|
|
|
|
|
I did think it was a cute reference to my inability to find the previous post about picture boxes.
|
|
|
|
|
No - if you look at my profile history, you'll see this in all my posts. I've been using it for 3 years now.
|
|
|
|
|
Yeah be very careful with anything that wraps GDI functionality. Even innocent looking things like Matrix implement IDisposable.
Check, double-check, etc.
|
|
|
|
|
I have the following code
public Download(string URL1)
{
Url = URL1;
WebClient client = new WebClient();
string[] s;
s = Url.Split(new Char[] { '/' });
client.DownloadFile(Url,@s[1]);
}
where s = url split by \
example www.yoururl.com\file.ext
short of sounding dumb, but to I have to fully qualify the save path or does it not assume to throw it in the folder when the file is executed...
|
|
|
|
|
EliottA wrote: where s = url split by \
example www.yoururl.com\file.ext
Isn't that supposed to be the name of the local file?
Why would you use another URL there?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|