M
m00n
Guest
Hi all. I have an app maintains a list of images from a directory. For each name, I need to open that image, get the bytes and send the bytes back to the caller, but... I also need to delete the image once I've processed it.
I have this function here pulls a file name from a list, that opens the image from the hard drive, gets the bytes into a byte array and tries to then delete the file from the disk. However, I keep getting an error
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'K:\TestImages\5.png' is denied.
public byte[] PullNextImage( )
{
string nextFile = DequeueNextImageName( );
if( nextFile == "" )
return null;
_currentImage = Image.FromFile( nextFile );
byte[] next = ImageToByteArray( );
_currentImage.Dispose( );
_currentImage = null;
if( next != null && next.Length > 0 )
File.Delete( nextFile );
return next;
}
So, I've pulled the bytes out of the image, I've disposed it, set it to null but I still get this error, what else am I supposed to do to do?
I know for a fact it's not a general file permissions issue with this file because if run this exact same function but I take out all the image processing, it will delete the file just fine.
public byte[ ] PullNextImage( )
{
string nextFile = DequeueNextImageName( );
if( nextFile == "" )
return null;
File.Delete( nextFile );
return null;
}
Rick
Continue reading...
I have this function here pulls a file name from a list, that opens the image from the hard drive, gets the bytes into a byte array and tries to then delete the file from the disk. However, I keep getting an error
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'K:\TestImages\5.png' is denied.
public byte[] PullNextImage( )
{
string nextFile = DequeueNextImageName( );
if( nextFile == "" )
return null;
_currentImage = Image.FromFile( nextFile );
byte[] next = ImageToByteArray( );
_currentImage.Dispose( );
_currentImage = null;
if( next != null && next.Length > 0 )
File.Delete( nextFile );
return next;
}
So, I've pulled the bytes out of the image, I've disposed it, set it to null but I still get this error, what else am I supposed to do to do?
I know for a fact it's not a general file permissions issue with this file because if run this exact same function but I take out all the image processing, it will delete the file just fine.
public byte[ ] PullNextImage( )
{
string nextFile = DequeueNextImageName( );
if( nextFile == "" )
return null;
File.Delete( nextFile );
return null;
}
Rick
Continue reading...