|
Something has changed for sure . But if I were the one who changed that something I wouldn't be here to pose this question.
I am not running anything which may lock the file. After all the file cannot even be created.
Running the environment as administrator even worsened things, as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path).
|
|
|
|
|
tiwal wrote: as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path). I would suggest you have a bug in your code which is leading to an invalid path somewhere. Use your debugger to step throught the code and see the exact values of the variables that are used to create the path.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Depends on what user the application is running under, rather than what access you have.
If this is winforms, then I would expect it to run under your user, but a service won't, for example.
Double check the folder address, and check the user ID it runs under - if it is complaining, then it is doing so for a reason!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
I am not sure I am understanding well. Tou mean , checking the folder I am trying to write to ?
|
|
|
|
|
Check the name, yes - make sure that the folder you are trying to write to is exactly the folder you think it is.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
hellow every body
I know this question is verey primary but I realy need its answer
how can i use poinrets in C#? please help me by an instance
|
|
|
|
|
You would also have to explain "what" the problem might be. If the problem is as broad as "I don't understand them", then the answer will be equally broad. For a general introduction to the topic, see MSDN[^].
|
|
|
|
|
tnx u
|
|
|
|
|
|
In order to use true pointers, you need to execute what is called unsafe code
This means you have to do two things:
1) Turn on unsafe code in your app (it is off by default). This is on the Build tab of your project properties.
2) Put the pointer use into an unsafe block. There is an example on the MSDN page: http://msdn.microsoft.com/en-us/library/chfa2zb8(v=vs.71).aspx[^]
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
It depends on what you need them for...
As others have said, you can use unsafe code. Alternatively, you can often use SafeHandle s, GCHandle s, GC.AllocHGlobal / GCFreeHGlobal along with IntPtr etc instead to achieve most things without needing to go quite as far as unsafe.
Without knowing the specifics then it is impossible to advise what is the best solution.
|
|
|
|
|
I doubt that your real need it to use pointers. Your need is to solve a problem that requires you to use pointers in languages like C and Pascal. That doesn't mean you need to use pointers in other languages.
In C#, every object is implicitly referenced through a "pointer" (which isn't a memory address, but an object reference). Say, to build a directed tree in a brother/son fashion, you declare your "myObject" class defines members "brother" and "son", both of class "myObj". Their values are not stored in the current node; the current node refers to ("has pointers to") the brother and son. There is no syntactical indication of this, because it is always so for class members.
Atomic members such as int and bool do reside in the class object, object members never do. You must be aware of this distinction - e.g. if you use the int member "age" as a method argument (without modifiers), a copy is provided to the method, but if you use "brother" as an argument, a reference ("pointer") is provided, not an object copy.
If you do not want to sent a copy of a single int, but a reference, you can use the Int class, which behaves just like your myObject instances: A reference is passed, not a copy of the value. But note that you don't need to use Int objects for allowing a method to change a parameter; you can add the modifier "ref" (or "out") to it, but you must add "ref"/"out" both in the formal declaration of the method and everywhere it is invoked.
The only time you need to handle pointers in C# is when interacting with unmanaged code, e.g. for a number of Windows system calls that are not directly available in C#. But you should avoid "using" pointers as much as possible: Treat them as opaque handles. Above all: Stay completely away from doing arithmetics on pointers! (Those who know what can and can't be done in that area need not ask questions about pointers in C#... )
|
|
|
|
|
Why isn't the following changing the value of the label LanguageSpoken?
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
LanguageSpoken.Text = cboUserLanguage.SelectedText;
}
private void Form1_Load(object sender, EventArgs e)
{
cboUserLanguage.SelectedIndex = 0;
LanguageSpoken.Text = cboUserLanguage.SelectedText;
}
Jon
|
|
|
|
|
cboUserLanguage.SelectedIndex = 0; Put a breakpoint on that line, and see what the SelectedIndex is before the assignment. If it is already 0 (could be set in the designer), then there will not be a "change".
|
|
|
|
|
Look here. Seems that there are problems when using it in click handler.
I suggest using cboUserLanguage.Items[cboUserLanguage.SelectedIndex].ToString(); instead.
|
|
|
|
|
suppose i have two image with same height and width. pic1.jpg & pic2.jpg. two image look pretty same with minimum difference. with the help of below routine we can get the difference between two images.this below routine is not my routine.
public class ImageDifferences
{
private static ILog mLog = LogManager.GetLogger("ImageDifferences");
public static unsafe Bitmap PixelDiff(Image a, Image b)
{
if (!a.Size.Equals(b.Size)) return null;
if (!(a is Bitmap) || !(b is Bitmap)) return null;
return PixelDiff(a as Bitmap, b as Bitmap);
}
public static unsafe Bitmap PixelDiff(Bitmap a, Bitmap b)
{
Bitmap output = new Bitmap(
Math.Max(a.Width, b.Width),
Math.Max(a.Height, b.Height),
PixelFormat.Format32bppArgb);
Rectangle recta = new Rectangle(Point.Empty, a.Size);
Rectangle rectb = new Rectangle(Point.Empty, b.Size);
Rectangle rectOutput = new Rectangle(Point.Empty, output.Size);
BitmapData aData = a.LockBits(recta, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData bData = b.LockBits(rectb, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData outputData = output.LockBits(rectOutput, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
try
{
byte* aPtr = (byte*)aData.Scan0;
byte* bPtr = (byte*)bData.Scan0;
byte* outputPtr = (byte*)outputData.Scan0;
int len = aData.Stride * aData.Height;
for (int i = 0; i < len; i++)
{
// For alpha use the average of both images (otherwise pixels with the same alpha won't be visible)
if ((i + 1) % 4 == 0)
*outputPtr = (byte)((*aPtr + *bPtr) / 2);
else
*outputPtr = (byte)~(*aPtr ^ *bPtr);
outputPtr++;
aPtr++;
bPtr++;
}
return output;
}
catch (Exception ex)
{
return null;
}
finally
{
a.UnlockBits(aData);
b.UnlockBits(bData);
output.UnlockBits(outputData);
}
}
}
}
after getting the difference how could i merge the difference on first image.
this below way we can merge
using (Graphics grfx = Graphics.FromImage(image))
{
grfx.DrawImage(newImage, x, y)
}
but we need to know the x & y from where the new image will be drawn on first image. can any one tell me how can i get the x & y position from the above routine called PixelDiff() thanks in advance.
tbhattacharjee
|
|
|
|
|
i have two images and i want to compare two image and want to get difference. i search google and found a link from where i copy paste the code for image comparison using win32 api. so this is the url http://blog.bobcravens.com/2009/04/create-a-remote-desktop-viewer-using-c-and-wcf/
here i am pasting the code.
private void button1_Click(object sender, EventArgs e)
{
Bitmap _prevBitmap = new Bitmap(@"d:\prev.jpg");
Bitmap _newBitmap = new Bitmap(@"d:\current.jpg");
Rectangle bounds = GetBoundingBoxForChanges(_prevBitmap, _newBitmap);
if (bounds == Rectangle.Empty)
{
}
Bitmap diff = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(diff);
g.DrawImage(_newBitmap, 0, 0, bounds, GraphicsUnit.Pixel);
g.Dispose();
// Set the current bitmap as the previous to prepare
// for the next screen capture.
//
diff.Save(@"d:\diff.bmp");
//return diff;
}
private Rectangle GetBoundingBoxForChanges(Bitmap _prevBitmap, Bitmap _newBitmap)
{
// The search algorithm starts by looking
// for the top and left bounds. The search
// starts in the upper-left corner and scans
// left to right and then top to bottom. It uses
// an adaptive approach on the pixels it
// searches. Another pass is looks for the
// lower and right bounds. The search starts
// in the lower-right corner and scans right
// to left and then bottom to top. Again, an
// adaptive approach on the search area is used.
//
// Note: The GetPixel member of the Bitmap class
// is too slow for this purpose. This is a good
// case of using unsafe code to access pointers
// to increase the speed.
//
// Validate the images are the same shape and type.
//
if (_prevBitmap.Width != _newBitmap.Width ||
_prevBitmap.Height != _newBitmap.Height ||
_prevBitmap.PixelFormat != _newBitmap.PixelFormat)
{
// Not the same shape...can't do the search.
//
return Rectangle.Empty;
}
// Init the search parameters.
//
int width = _newBitmap.Width;
int height = _newBitmap.Height;
int left = width;
int right = 0;
int top = height;
int bottom = 0;
BitmapData bmNewData = null;
BitmapData bmPrevData = null;
try
{
// Lock the bits into memory.
//
bmNewData = _newBitmap.LockBits(
new Rectangle(0, 0, _newBitmap.Width, _newBitmap.Height),
ImageLockMode.ReadOnly, _newBitmap.PixelFormat);
bmPrevData = _prevBitmap.LockBits(
new Rectangle(0, 0, _prevBitmap.Width, _prevBitmap.Height),
ImageLockMode.ReadOnly, _prevBitmap.PixelFormat);
// The images are ARGB (4 bytes)
//
int numBytesPerPixel = 4;
// Get the number of integers (4 bytes) in each row
// of the image.
//
int strideNew = bmNewData.Stride / numBytesPerPixel;
int stridePrev = bmPrevData.Stride / numBytesPerPixel;
// Get a pointer to the first pixel.
//
// Note: Another speed up implemented is that I don't
// need the ARGB elements. I am only trying to detect
// change. So this algorithm reads the 4 bytes as an
// integer and compares the two numbers.
//
System.IntPtr scanNew0 = bmNewData.Scan0;
System.IntPtr scanPrev0 = bmPrevData.Scan0;
// Enter the unsafe code.
//
unsafe
{
// Cast the safe pointers into unsafe pointers.
//
int* pNew = (int*)(void*)scanNew0;
int* pPrev = (int*)(void*)scanPrev0;
// First Pass - Find the left and top bounds
// of the minimum bounding rectangle. Adapt the
// number of pixels scanned from left to right so
// we only scan up to the current bound. We also
// initialize the bottom & right. This helps optimize
// the second pass.
//
// For all rows of pixels (top to bottom)
//
for (int y = 0; y < _newBitmap.Height; ++y)
{
// For pixels up to the current bound (left to right)
//
for (int x = 0; x < left; ++x)
{
// Use pointer arithmetic to index the
// next pixel in this row.
//
if ((pNew + x)[0] != (pPrev + x)[0])
{
// Found a change.
//
if (x < left)
{
left = x;
}
if (x > right)
{
right = x;
}
if (y < top)
{
top = y;
}
if (y > bottom)
{
bottom = y;
}
}
}
// Move the pointers to the next row.
//
pNew += strideNew;
pPrev += stridePrev;
}
// If we did not find any changed pixels
// then no need to do a second pass.
//
if (left != width)
{
// Second Pass - The first pass found at
// least one different pixel and has set
// the left & top bounds. In addition, the
// right & bottom bounds have been initialized.
// Adapt the number of pixels scanned from right
// to left so we only scan up to the current bound.
// In addition, there is no need to scan past
// the top bound.
//
// Set the pointers to the first element of the
// bottom row.
//
pNew = (int*)(void*)scanNew0;
pPrev = (int*)(void*)scanPrev0;
pNew += (_newBitmap.Height - 1) * strideNew;
pPrev += (_prevBitmap.Height - 1) * stridePrev;
// For each row (bottom to top)
//
for (int y = _newBitmap.Height - 1; y > top; y--)
{
// For each column (right to left)
//
for (int x = _newBitmap.Width - 1; x > right; x--)
{
// Use pointer arithmetic to index the
// next pixel in this row.
//
if ((pNew + x)[0] != (pPrev + x)[0])
{
// Found a change.
//
if (x > right)
{
right = x;
}
if (y > bottom)
{
bottom = y;
}
}
}
// Move up one row.
//
pNew -= strideNew;
pPrev -= stridePrev;
}
}
}
}
catch (Exception ex)
{
int xxx = 0;
}
finally
{
// Unlock the bits of the image.
//
if (bmNewData != null)
{
_newBitmap.UnlockBits(bmNewData);
}
if (bmPrevData != null)
{
_prevBitmap.UnlockBits(bmPrevData);
}
}
// Validate we found a bounding box. If not
// return an empty rectangle.
//
int diffImgWidth = right - left + 1;
int diffImgHeight = bottom - top + 1;
if (diffImgHeight < 0 || diffImgWidth < 0)
{
// Nothing changed
return Rectangle.Empty;
}
// Return the bounding box.
//
return new Rectangle(left, top, diffImgWidth, diffImgHeight);
}
when GetBoundingBoxForChanges() call then i am getting error and error message is Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
error occur at this code if ((pNew + x)[0] != (pPrev + x)[0])
so i am not being able to find out the reason. how to fix this error. please guide. thanks
tbhattacharjee
|
|
|
|
|
Tridip Bhattacharjee wrote: so i am not being able to find out the reason. how to fix this error. please
guide. thanks
If you get an error with code that you got from someone's blog, the standard thing to do is approach the person who wrote the blog and ask them what's wrong. They wrote the code, so they are best placed to help.
|
|
|
|
|
This is my first attempt at C# sharp so please forgive me if I'm a bit slow at absorbing anything.
When my code compiles it does not appear to process the files in the given directory. I specified that if there are no files in the directory to pop a message box up, so when the code is run with no files in the directory I get no message box leading me to belive the the "StartProcessing" segment has not been called.
Is the "StartProcessing" Segment been called? If it is thats fine I and I shall start to look else where for my error.
Here is a sample of how I have layed out the begining of the code:
namespace MyName
{
class Program
{
private static void Main()
{
}
private static void StartProcess(string dirPath)
{
DirectoryInfo dir = new DirectoryInfo(@"C:\SomeDir");
foreach (FileInfo finfo in dir.GetFiles("*.doc"))
MISC. CODE
MISC. CODE
|
|
|
|
|
First of all, in the example here you haven't actually called StartProcess from anywhere. You have to add a call to the method if you want it to run. Secondly, you are passing in dirPath and then doing nothing with it. Finally, Main should be public, not private. I would change your code to do something like this:
namespace MyName
{
class Program
{
public static void Main()
{
StartProcess(@"c:\somedir");
}
}
private static void StartProcess(string dirPath)
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
......
}
}
|
|
|
|
|
Thank you very much for this, I misunderstood how the code was processed. I was under the impression that static Methods would be processed in order one after another... I now know this is wrong.
Thank you for helping me out, I feel like I've taken another small step (probably a very smal baby step) in learning C#.
|
|
|
|
|
I'm glad I could help, and good luck with your C# journey.
|
|
|
|
|
|
Thank you Richard, I shall have a google for it. By the way I'm loving the creative signature
|
|
|
|
|
Pete O'Hanlon wrote: Finally, Main should be public, not private.
You'd have thought that, but the entry point is special and will still be found even when hidden away inside a private nested class:
class Program {
private class NestedClass {
private static void Main() {
Console.WriteLine("Hello");
Console.ReadLine();
}
}
}
Alan.
|
|
|
|
|