|
Any faster method to change the contrast of ab image......... OTHER than that unlock and unsafe method its very slow...... Is there anything else?????????
|
|
|
|
|
You can adjust brightness and contrast through a matrix operation in GDI+.
// return matrix for the specified contrast
public static float[][] GetContrastMatrix( int percent )
{
// perform contrast by setting the scale and offset at the same time
// calculate the scale and offset
float v = 0;
if ( percent > 0 )
{
// range from 0.0 (no change) to 3.8 (high contrast)
v = 0.0195F * percent;
v *= v;
}
else
{
// negative value, -1.0 is gray and 0.0 is no change
v = 0.009F * percent;
}
float scale = 1 + v;
float offset = v / 2;
// setup the matrix
float[][] matrix =
{
new float[]
{ scale, 0, 0, 0, 0 }, new float[]
{ 0, scale, 0, 0, 0 }, new float[]
{ 0, 0, scale, 0, 0 }, new float[]
{ 0, 0, 0, 1, 0 }, new float[]
{ -offset, -offset, -offset, 0, 1 } };
return matrix;
}
That returns a contrast matrix. This code:
ColorMatrix cm = new ColorMatrix( matrix );
ImageAttributes attr = new ImageAttributes();
attr.SetColorMatrix( cm );
Creates an ImageAttributes object that uses the matrix. Then the Graphics class has a DrawImage overload ( or more ) that take this ImageAttributes class as a parameter.
I should write an article on this, to complement my articles showing the 'lock bits' way of doing things.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanx a lot.....
Christian Graus wrote: You can adjust brightness and contrast through a matrix operation in GDI+.
Can u plz send me the matrix operation for brightness and I also want little explaination abt how these operations works....where can I find it??????
|
|
|
|
|
|
I've the following Problem. I need to populate a TreeView from a Database.
The Table looks like this:
Typename|rule.id|Rule_Prio|Level|Typename
"Vehicle","Vehicle=Car+Pickup",1,2,"car"
"Vehicle","Vehicle=Car+Pickup",1,2,"Pickup"
"car","car=carWithoutTrailer",2,1,"carWithoutTrailer"
"Truck","Truck=HeavyTruck+LightTruck",1,1,"HeavyTruck"
"Vehicle","Vehicle=Truck",2,2,"Truck"
"Truck","Truck=HeavyTruck+LightTruck",1,1,"LightTruck"
"car","car=carWithTrailer",1,1,"carWithTrailer"
"Pickup","Pickup=PickupWithoutTrailer",1,1,"PickupWithoutTrailer"
The Vehicle is the rootNode. It's no problem to get it from the Database. One of my biggest problems is: no Primary key exists for it. So it's hard for me to find a recursive solution. I think a Picture says more than words.
It should look like this:
Picture of how the Tree should look like
The Rule_Prio is always a node after nodes to group them.
Ive already created a connection to the Database. Created a DataAdapter and filled it with a DataSet which contains the Table.
Every try to build this tree leads to a stackoverflow or leads to different problems.
I read all the TreeView Tutorials in here but there recursive solutions didn't help me much because they often work on a primary key or better an id which is an int and which is autoincremented.
Any ideas?
-- modified at 6:21 Sunday 4th March, 2007
|
|
|
|
|
FYI - your link does not work.
I'm not clear on Rule_Prio or Level but here's one thought:
Make sure the list is sorted such that the parent nodes come before child nodes. e.g. in your list "HeavyTruck" is listed before "Truck" has been added to "Vehicle".
Use Typename to find the parent node.
Add current item as child to parent node.
It is relatively slow since you must find the parent for each addition.
Good Luck.
|
|
|
|
|
Ok thx.
I corrected the link. But i'm not able to get the priority into this.
|
|
|
|
|
Not sure I understand you. Are you having difficulty adding the priority node to its parent node? Why?
|
|
|
|
|
hey,
i want to make a window that will dynamically generate the copy of background application,, mention you i wana generate dynamic copy , so that i can make changes in that copied window...... whenever the window is draged n droped it should create the copy of background which it is covering....
plz help me... i m in real need
sushant kaura
sushant kaura
|
|
|
|
|
hi,
Any body please give me information ,About
collection class . And its interfaces implementations.
(or) where i found ?
|
|
|
|
|
|
thank you for providing information.
|
|
|
|
|
Hi guys
I have a problem when I use an Add-in to word, I want to get the filename / path of opened document.
(i.e i have a opened a document in word, now when i click my button it should return the filename / filepath of opened word document.
Thank you!
M. Nauman Yousuf
|
|
|
|
|
How do i get the byte[] associated to the System.Drawing.Bitmap class???
a fast and helpful answer is requier
KainPlan.
|
|
|
|
|
|
Yeah i know this... it works... but the display works with 8 bit per pixel and the result of viewing the bitmap is not what it meant for. (sry for bad english) I need to Convert the Bitmap or the array but it all happens in a rendering thread at 10fps and a convert like this:
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
byte b = 0;
if (bmp.GetPixel(x, y).B < 128)
b = 128;
arr_bytes[i] = b;
i++;
}
}
is too slow.
Edit:
(if b >= 128 the display draws a black pixel.)
|
|
|
|
|
Use System.Drawing.Bitmap.LockDIBits() and System.Runtime.InteropServices.Marshal.Copy
|
|
|
|
|
yeah this works too!!! but its the problem of the 8bits again...
the Display works with 160x43x1 how to convert the 160x43x4 that its shown correct on the display...
Its in a rendering Thread, means no slow actions like for or while loops. i need something like to get only every 4th bit of the array i think... 32bpp to 8bpp...
Or maybe first convert the System.Drawing.Bitmap from 32bpp to 8bpp and then Marshall.Copy the bytes..
Any ideas??? Sry for bad english
|
|
|
|
|
AHHHHH!!!!!! I GOT IT
//Preform bit reading of bmp.
Draw.Rectangle rect = new Draw.Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = bmp.Width * bmp.Height * 4;
byte[] rgbValues = new byte[bytes];
//Marshal copy the bits at ptr to rgbValues at 0 for a size of bytes.
System.Runtime.
InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
bytes = bmp.Width * bmp.Height * 1;
byte[] bValues = new byte[bytes];
int i = 0;
//Convert into a Displayable kind.
while (i != bytes)
{
bValues[i] = rgbValues[i * 4];
i++;
}
lgbmp.pixels = bValues;
a little bit worse but it works with no timing issues!!!
|
|
|
|
|
I'm not interested in simple solution of getting the url and opening IE from process.start(IE,url)
the closest thing i had in mind is : when i right click the link from axWebBrowser and choose "open in new window" it opens it in new IE window, so I'm looking for a way to imitate it somehow and perform the same action on left mouse click on that link (and it will open a new IE window), like re-routing from axWebBrowser into IE.
again, im not interested in the url that is being opened on "open in new window" its more complicated than that, thats why I'm looking for a way to "re-route" from axWebBrowser into IE.
thx ahead!
|
|
|
|
|
Hello experts,
I'm pondering on the matter for some time now...
How can I tell which object types are managed types, and which are unmanaged?
I was writing a Dispose(bool disposing) method for one of my classes, and the question poped up...
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}
}
disposed = true;
}
How do I know which objects should be disposed of in the if (disposing) {...} block?
I guess a FileStream and maybe other streams are unmanaged and should be disposed outside of the block.
What about sockets, timers, etc.?
How to tell??
Thanks in advance,
Shy.
|
|
|
|
|
You should treat any class that implements IDisposable as containing unmanaged resources.
Some classes, like for example MemoryStream, does implement IDisposable eventhough it doesn't contain any unmanaged resources. You should dispose of it anyway, partly just to follow the pattern, but also because the memory management works better if you dispose of all disposable objects.
---
single minded; short sighted; long gone;
|
|
|
|
|
So what should the if (disposing) { ... } block contain?
Should I simply set each non-disposable object to null?
|
|
|
|
|
If an object implements IDisposable , then it most probably implements a finalizer too. In that case, you cannot call Dispose outside the if (disposing) {...} block. The unmanaged resource cleanup is only for unmanaged resources that don't have a Dispose/Finalizer (things like handles you opened yourself).
protected void Dispose(bool disposing)
{
if (disposing)
{
}
}
|
|
|
|
|
That code block is used for anything that you have to do to put your object into an unusable state, as an object is not supposed to be usable after it has been disposed.
You don't have to dereference objects. When the last reference to your object goes away, the references that it contains doesn't count any more.
---
single minded; short sighted; long gone;
|
|
|
|
|