|
Hello,
This may seem a stupid question to you, but i wanted to know that i downloaded the .netframework 3.0 and an addon for Visual stidio express C#, but its not giving up any visual development environment. how will that activate. Please guide..
Rahul.
|
|
|
|
|
The visual studio extensions do not include any visual designer add ons. The visual designer ("Cider") is a separate tool.
|
|
|
|
|
Dear Friends,
I am using the following code to read colored (24 bit) image into array, but when
I want to read black and white (1 bit image) it gives error
"AccessViolationException unhandled" "Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.":
public static bool identifyLine(Bitmap imtooperated)
{
ArrayList blah = new ArrayList();
BitmapData bmData = new BitmapData();
Rectangle rect = new Rectangle(0, 0, imtooperated.Width,
imtooperated.Height);
bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly,
imtooperated.PixelFormat);
int stride = bmData.Stride;
int range=0;
unsafe
{
byte* p = (byte*)(void*)bmData.Scan0;
for (int y = 0; y < imtooperated.Width; y++)
{
for (int x = 0; x < imtooperated.Height; x++)
{
blah.Add(p[range]); //here error comes
range++;
}
p += 1;
}
p += stride;
}
imtooperated.UnlockBits(bmData);
return true;
}
Please help.
|
|
|
|
|
dear code_explore
replace this line
bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly,imtooperated.PixelFormat);
by
bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly,PixelFormat1bppIndexed,imtooperated.PixelFormat);
you dont specify format for reading
reqarding...
eng. rizgar
|
|
|
|
|
Hi,
A couple of questions...
1) How do I capture the esc-key pressed event?
2) How do I track the progress of an sql query thrown to the server so that I can use this value to feed to my progress bar?
Thanks!
|
|
|
|
|
j11Software wrote: How do I capture the esc-key pressed event?
There is no specific event for the escape key. You capture it like any other key.
j11Software wrote: How do I track the progress of an sql query thrown to the server so that I can use this value to feed to my progress bar?
You don't. The server does not indicate the partial progress of a query.
If you are running a stored procedure that concists of several queries, you could store the status for each step into a table, and query that table to find out the progress.
---
Year happy = new Year(2007);
|
|
|
|
|
FYI,
if you want the ESC key to mean the same thing as pressing a specific Button on the
current form, you can set the Form.CancelButton property to point to that Button.
Luc Pattyn
|
|
|
|
|
How can I reduce image quality when I'm saving an image to reduce its size?
Thanks
|
|
|
|
|
One simple way is to change the resolution using Bitmap.SetResolution() method to a less value.
Regards
|
|
|
|
|
Thanks for reply but it doesn't help. I want to reduce file size.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
You can use the Quality encoder parameter, which works only with the JPEG encoder. Here's how to specify a quality level when saving an image:
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo codec = null;
foreach(ImageCodecInfo c in codecs)
{
if(c.MimeType=="image/jpeg")
{
codec=c;
break;
}
}
EncoderParameters encoderParams=new EncoderParams(1);
EncoderParameter encoderParam=new EncoderParameter(Encoder.Quality, 90L);
encoderParams.Param[0]=encoderParam;
bmp.Save(filename,codec,encoderParams);
|
|
|
|
|
Thanks for reply, but my files are in tif format.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Unless the TIFF file uses JPEG compression (which is possible, but kind of pointless), the compression is lossless. That means that you can not change the quality of the compression as the compression does not make any quality compromises.
Unless you specifically need the TIFF format, you could try the PNG format instead. It is also lossless, but compresses a lot better. If you want lossy compression, use the JPEG format.
---
Year happy = new Year(2007);
|
|
|
|
|
I would like for the page to load and then for a process to kick off. The results of the process would then be updated on the page (via AJAX if I can ever get it to work). How do I do this?
|
|
|
|
|
It doesn't work that way. Well, it's possible using server push, but that requires that you start a component in the browser that establishes a permanent connection between the browser and the server, and even then you would have to re-attach it to the running process on the server.
Normally everything that you send between the server and the browser is initiated by the browser. The server can not send anything to the browser unless the browser is first sending a request to the server.
You can use AJAX to poll the server at a specific interval, so that the server could respond with the result. The running threads would have to store the results in a static list, so that the AJAX request could pick up the lastest result from a specific thread. You would also have to give each thread a unique identifier to identify the results, and keep the identifier in the page, so that it could be sent in the AJAX call in order to pick up the result from the correct thread.
---
Year happy = new Year(2007);
|
|
|
|
|
Wow, so is there an easy way to have an update page could be easily updated with information regarding the process that was kicked off on the page load event?
|
|
|
|
|
That depends on what you mean by easy... There is nothing in it that is very complicated, but it's certainly not something you just drag and drop on your page.
---
Year happy = new Year(2007);
|
|
|
|
|
Hi All,
how many types of authentication modes available in .Net?
how can we Implement forms-based cookie-less authentication in our application? i mean where & how can we set this Property?
thanks in advance,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Cookies are not used for authentication, they are used to maintain settings between sessions. That's not really the same thing. You can make a cookie keep authentication settings, but at the point of login, your authentication system will verify those details, all the cookie provides is persistence.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hey all,
I'm working on a small program that manipulates an XML file, like the one below:
<code><?xml version="1.0" encoding="UTF-8"?>
<Root>
<patient>
<name>Jack Sparrow</name>
<gender>female</gender>
<dob>1/1/1940</dob>
<age>67</age>
<parentsnames>n/a</parentsnames>
<maritialstatus>divorced</maritialstatus>
<streetaddress>123 Anywhere Dr</streetaddress>
<homephone>111-111-1111</homephone>
<workphone>222-222-2222</workphone>
<cellphone>333-333-3333</cellphone>
<citystatezip>Somewhere/ST/12345</citystatezip>
<iseval>1</iseval>
<dateinitialeval>1/1/2006</dateinitialeval>
<lengthinitialeval>1.4</lengthinitialeval>
<isinter>0</isinter>
<dateinitialinter>
</dateinitialinter>
<lengthinitialinter>0</lengthinitialinter>
<notes>Dr. Don</notes>
<supervisor>1</supervisor>
<attributes>
<speech>0</speech>
<language>1</language>
<articulation>0</articulation>
<hearing>1</hearing>
<tbi>0</tbi>
<cva>1</cva>
<voice>0</voice>
<fluency>0</fluency>
</attributes>
</patient>
</Root></code>
I am trying to make the script remove an old entry, then add a new entry at the end of the XML file (as you can see, this file only has one entry). I am trying to do the removing using the following code snipped:
<code> string filename = "data.xml";
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(filename);
}
catch (System.IO.FileNotFoundException)
{
//Do nothing
}
string expr = "/Root/patient[name='" + this.clientName.Text + "']";
XmlNode node;
node = xmlDoc.SelectSingleNode(expr);
node.ParentNode.RemoveChild(node);</code>
(this.clientName.Text contains the name of the client). The expression is matching just fine, if I add a MessageBox() to output node.OuterXml, everything displays fine. However, the RemoveChild() does nothing (it doesn't remove the field that was matched). The script goes on to write the edited entry, so I end up with two entries that are almost the same instead of a new one in place of an old one. What's wrong?
Let me know if you need any more information.
|
|
|
|
|
You really want to look for the patient using a better unique Id than name, and then you want to keep a reference to the existing patient node. This code will remove the name node only, which is obviously not what you want. It's probably easier to delete the existing record than to write code that either updates or edits, but either way, name is not a good unique Id, and you want to delete the patient record, not the name node.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I am rather new to XML, so I tried your code as an exercise.
I added some logging to see intermediate states.
It did remove the entire patient record from xmlDoc, as you would have hoped.
To change the file, I guess you would need to terminate with xmlDoc.Save
Luc Pattyn
|
|
|
|
|
I have a function that will divide a loop iteration among threads. Each thread will be given its portion of work to do by giving it the array to iterate through and the start and end index that will be the range of indexes it will work on. I'm also assuming that I will not need to synchronize the access to the array since it works on each variable independently but I may be wrong. Here is what I have.
public Range[] ReturnIndexRanges(long[] indexes)
{
Range[] ranges = null;
Thread[] threads = new Thread[Environment.ProcessorCount];
long length = ((end - start) + 1) / Environment.ProcessorCount;
_start = start;
foreach (Thread t in threads)
{
t = new Thread(new ParameterizedThreadStart(ReturnRangesOfIndexes));
t.Start(new ThreadedReturnRangesOfIndexData(ranges, indexes, _start, length - 1));
_start += length;
length = end - length + 1;
}
return JoinDividedRanges(ranges);
}
private class ThreadedReturnRangesOfIndexData
{
public ThreadedReturnRangesOfIndexData(Range[] ranges, long[] indexes, long start, long end)
{
ranges_out = ranges;
indexes_in = indexes;
this.start = start;
this.end = end;
}
public long start, end;
public long[] indexes_in;
public Range[] ranges_out;
}
The ThreadedReturnRangesOfIndexData class is just a small class that hold some information such as the array of the indexes being passed into the method and the array of Ranges that will be returned. It will be like ref but since it is an array I do not need to add ref or out to it because an array is a reference type.
What I need is to figure out how to divide the indexes up evenly in the ReturnIndexRanges method at the top. This is my first attempt at creating a multi-threaded program so I would appreciate some tips if you have any. Should I just forget about threading?
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
Hello again,
I have some thoughts about this:
1) I hope you dont go through all this if ProcessorCount==1
or maybe you should, just to make sure it is also correct in that case ?
2) in my experience it works a lot easier when you never use end, but instead
use end+1 (saves a lot of mistakes, and it fits the for-loop paradigma).
3) I would not try to divide the job in exactly even parts, when you split
100 in 48+52 it won't matter that much.
4) I would be very careful not to have data that resides in the same cache line
(more precisely in addresses that differ by less than the cache line size)
be written by different processors. It would cause a lot of invalidate,
flush and reload operations, and would be devastating for performance.
And yes this is hard to achieve in a high-level language.
I hope but am not absolutely sure, arrays are always allocated at
an address that is a multiple of a sufficiently high power of 2
(say a multiple of 256 B). You can check this somewhat by experimenting,
better is to have it specd somewhere, but I dont recall having seen that.
5) 3+4 together means: I would, still thinking of arrays, split on
boundaries that correspond to 256 B or more, hence round up to 64
when dealing with 4B ints, etc.
6) I do recall some Intel articles that suggested making structs artificially
larger when you can afford it, just to achieve my point 4 (e.g. for control
data, such as task control blocks).
One of them showed how you can really kill a multi-processor system: have
two threads do spin locks on 2 data items that belong to the same cache line !
7) on the other hand, if you over-align your data, you increase the possibility
of cache trashing; example: if you need repetitive access to only 1000 bytes,
but all these bytes are at a stride of 1KB, they would constantly miss in
a cache even as big as 2MB, since cache associativity nowadays is something
like 8-way, so there would only be 8 cache line candidates to cache the
requested data (the cache line candidate in each way being determined by
the lowest address bits (but excluding those that correspond to the
cache line width).
8) in conclusion, I suggest you use variables for your basic parameters
(such as number of processors, estimated safe allignment (my 256 B above), etc.
And once you have it running, just do some more experiments with slightly
different values for those variables, just to see what really helps.
Good luck, and please keep posting your progress.
Luc Pattyn
|
|
|
|
|
Well thanks for the information. I think I will stick to the single threaded version of my method until I do more research. I didn't even think about the cache and aligning the data. I wanted to get the absolute max performance I could but it seems that will be much more complex than I thought it would. Here is the single threaded version. Its much simpler.
/// <summary>
/// Finds the ranges that may be in a sorted array of indexes. A range is one or more indexes that increment
/// by one, an array containing 6,7,8,10,400,401,402 contains three ranges 6-8, 10, and 400-402.
/// </summary>
/// <param name="indexes">A sorted array of indexes to search.</param>
/// <returns>An array of Ranges.</returns>
public Range[] FindIndexRanges(long[] indexes)
{
if (indexes.LongLength == 0)
return new Range[0];
if (indexes.LongLength == 1)
return new Range[] { new Range(indexes[0], indexes[0]) };
Range[] ranges = new Range[1];
bool resize = false; //this should be true after 1 range has been found
long firstIndex = indexes[0];
long lastIndex = indexes[0];
for (long i = 1; i < indexes.LongLength; i++)
{
if (indexes[i] == indexes[i - 1] + 1)
{
lastIndex++;
if (i != indexes.LongLength - 1)
continue;
}
if (resize)
Array.Resize<Range>(ref ranges, ranges.Length + 1);
ranges[ranges.Length - 1] = new Range(firstIndex, lastIndex);
firstIndex = lastIndex = indexes[i];
resize = true;
}
return ranges;
}
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|