|
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.
|
|
|
|
|
I have a nice set of C# solutions on my machine.
Solution A and B compiles a few exe and dll.
Solution C generates a couple of MSI with WIX (it gets it files from the output of the two other solutions).
It work well on my machine.
When I try to compile it with a TFS Build Server though things differ.
1 - all the exe and dll are going to a single folder
2 - as the files are not compiled in the same places wix cannot find the exe and libraries.
I can think of a few ways to fix this, but I can't help but wonder, what did I do wrong?
|
|
|
|
|
i want to know what is Gaussian blur of image how to do this.I am working on canny edge detection where i want to use Gaussian mask but i don't know mathematics behind it.
|
|
|
|
|
There is a good amount of hits on Google for Gaussian Mask[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
|
I am using WCF services with Thread Pool concepts in the application using Oracle Database. The application has a Scheduling Workflow, where there will be multiple Jobs scheduled at the same time. The expected behavior is that, once the scheduler is triggered, all the jobs should be started parallel and at the background, various process are run.
All the jobs are not started in parallel. Say for example, if there are 20 jobs scheduled, only 15 are getting started and remaining are struck.
It results in Oracle Connection request timed out error.
Options Tried:
As the application uses PerSession and Concurrency mode as Multiple. The binding is netTCPBinding. Tried this could have been a WCF Throttling issues. So modified the Throttling parameters as well. But still results in Oracle error.
Any help would be appreciated.
|
|
|
|
|
rajaron wrote: Say for example, if there are 20 jobs scheduled, only 15 are getting started and remaining are struck.
It results in Oracle Connection request timed out error.
That means that 20 connections are reading from the same tables? Or are they also writing to those tables?
|
|
|
|
|
Hello,
I'm working on a small project wich requires me to run some code as a different users , (not the windows users)
I.e. user starts the program and he/she is required to login first, then there allowed to run a piece of code.
My login code looks like this :
private bool Authenticate(string userName, string password, string domain = null)
{
bool authentic = false;
try
{
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
authentic = context.ValidateCredentials(userName, password);
}
}
catch (DirectoryServicesCOMException) { }
return authentic;
}
Wich works,
But i cannot execute the rest of my code.
I've tried to use Impersonation Class but it results in an "Catasthropic failure"
The code blow is how i use the impersonation,
it happends after a button_click event
using (new Impersonator(txtGebruiker.Text, txtDomein.Text, txtPw.Text))
{
string profile = GetProfilePath(txtProfiel.Text);
txtLog.Text = profile;
}
I think im using the impersonation wrong ,
Any tips or suggestions are welcome
Thanks in advance
|
|
|
|
|
If you have a problem using the code in an article, it's usually best to post the question to the message board at the end of the article[^], since the author of the article is the best person to help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
From your code that's posted with the question on the article;
string profile = dirEntr.Properties["profilePath"][0].ToString();
dirEntr.Close();
If the first line throws an exception, it'd be logical for the second line to fail. The first line contains multiple statements, which I'd prefer to see split over several lines (to accommodate debugging), like this;
object profilePath = dirEntr.Properties["profilePath"];
string profile = Convert.ToString(profilePath[0]);
It might be that the property "ProfilePath" doesn't return a value; you'd put a breakpoint there and step through it. As a sidenote, you did see the warning in the article?
Please note: The user context that initiates the impersonation (i.e. not the user context to which it is switched to) needs to have the "Act as part of operating system" privilege set.
|
|
|
|
|
Hi,
Please anybody knows how to convet the html file into XML file using C#. I need to convert whole html file into XML file.
Thanks...
modified 12-Dec-12 3:18am.
|
|
|
|
|
chittu dinesh wrote: Please anybody knows how to convet the html file into XML file using C#.
Yes I do.
chittu dinesh wrote: Its urgent.
I couldn't care less. It's not urgent to me. Never use it's urgent in a forum posting - we don't work for you so your sense of urgency is completely irrelevant.
The solution you are looking for is to use the HTML Agility Pack[^]. Bear in mind, though, that an HTML page may be so badly formed that it cannot be represented as XML.
|
|
|
|
|
Hi,
Thanks.
|
|
|
|
|
If it's valid XHTML, then it's already XML. If you mean translate it to a particular schema, you can do that with XSLT.
If it's typical Internet HTML, then it isn't valid XML, and you will have to construct some sort of state-based reader that makes reasonable guesses about what non-XML markup actually means (i.e. unclosed <li>s and <p>s, unmatched chevrons, tags with naked attributes, etc).
|
|
|
|
|