|
|
Hello gurus,
Given a color, I'd like to know how to calculate the nearest color from the standard list?
For example:
given the color: FFD3D3D3, the function will return FFD7D7D7 which is Color.LightGray
Color clr=new Color(0xd3, 0xd3, 0xd3);<br />
Color nearestColor=GetNearestColor(clr);
will return Color.LightGray to nearestColor
Can anybody help me to solve this?
Thanks in advance.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
|
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows:
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating
compiler...", 3, 1);
// Create code compiler
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
// Create compiler parameters
PopupProgress.Display("Compiling Installer...", null, "Compiling",
"Configuring compiler...", 3, 2);
CompilerParameters cparams = new CompilerParameters();
cparams.Evidence = new
System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
cparams.GenerateExecutable = true;
cparams.GenerateInMemory = false;
cparams.IncludeDebugInformation = false;
//cparams.MainClass = "S2CIPInstaller.Main";
//cparams.OutputAssembly = step4.CompileTarget;
cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true);
cparams.ReferencedAssemblies.Add("System.dll");
cparams.ReferencedAssemblies.Add("System.Drawing.dll");
cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
// cparams.ReferencedAssemblies.Add("System.XML.dll");
cparams.ReferencedAssemblies.Add(m_basePath +
@"temp\SynapticEffect.Collections.dll");
cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll");
cparams.CompilerOptions = "/resource:\"" + m_basePath +
"temp\\S2CIPInstaller.resources\"";
//cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources";
// Compile
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3);
CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code);
PopupProgress.Remove();
int errCount = 0;
for (int i=0; i<results.errors.count; i++)
{
="" if="" (!results.errors[i].iswarning)
="" errcount++;
}
if="" (errcount=""> 0)
{
MessageBox.Show(this, "There were errors during compilation. Installer not created.");
}
else
{
MessageBox.Show(this, "Installer successfully created!");
}
When I use the code provider from my own program, I get the following error (only visible after attaching with a debugger. I apologize for the coded .exe name --> yodjgmq_.exe):
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure "S2CIPInstaller.resources" was correctly embedded or linked into assembly "yodjgmq_". baseName: S2CIPInstaller locationInfo: DatGen.S2CIPInstaller resource file name: S2CIPInstaller.resources assembly: yodjgmq_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Does anyone know why the installer app works when compiled with VS.NET, but not with the CSharpCodeProvider and ResourceWriter classes from the .NET Framework from my own code? Any insight is greatly appreciated.
Jon Rista
jrista@hotmail.com
|
|
|
|
|
I'm kind of desperate at this point. I've done everything I can to get my compiled program to work, but it keeps telling me hte resources are missing, even though hex-editing the .exe shows it there.
|
|
|
|
|
Help!!!
I am trying to create black and white images of screen shots I have captured from the desktop.
I am able to do everything other than produce black and white images.
I can create colour images but our FileNet IDM viewer cannot cope with the type of tiff file created.
So, how do I create a black and white image from the desktop colour image?
The code I am using only gives me the option to select colour image formats. e.g. Below uses PixelFormat.Format16bppRgb555.
HOW CAN I GET A BLACK AND WHITE IMAGE FROM THE BITMAP?
Any help gratefully received.
Bitmap bmPhoto = new Bitmap(imageWidth, imageHeight, PixelFormat.Format16bppRgb555);
bmPhoto.SetResolution(img.HorizontalResolution, img.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(img, new Rectangle(0, 0, imageWidth, imageHeight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
grPhoto.Dispose();
GC.Collect();
Colin.
|
|
|
|
|
You would have to operate on each pixel, and set the color for each component (except alpha) to the average of R,G,B. You can do this with GetPixel/SetPixel, but its extremely slow. Using pointers in unsafe code is faster by several magnitudes:
// For 32bit image
public unsafe void ReduceToGrayscale(Bitmap bmp)
{
PixelFormat pf = PixelFormat.Format32bppArgb;
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF rf = m_bitmap.GetBounds(ref unit);
Rectangle r = Rectangle.FromLTRB((int)rf.Left, (int)rf.Top, (int)rf.Right, (int)rf.Bottom);
// OR: Rectangle r = Rectangle.Round(rf);
BitmapData bd = bmp.LockBits(r, ImageLockMode.ReadWrite, pf);
byte* pixel = (byte*)bd.Scan0;
byte r, g, b, avg;
for (int y=0; y<bd.width; y++)
="" {
="" for="" (int="" x="0;" x<bd.height;="" x++)
="" b="*(pixel);
" g="*(pixel+1);
" r="*(pixel+2);
" agv="(r+b+g)/3;
" *(pixel)="avg;
" *(pixel+1)="avg;
" *(pixel+2)="avg;
" *(pixel+3)="0xFF;" alpha
="" pixel="" +="4;
" }
="" }
="" bmp.unlockbits(bd);
}
this="" code="" works="" a="" 32bit="" image.="" 16bit="" image,="" you="" will="" have="" to="" take="" into="" account="" the="" stride="" length.="" bitmap="" image="" in="" .net,="" every="" always="" uses="" enough="" memory="" full="" mage,="" even="" if="" its="" just="" 8bit="" indexed.="" so,="" of="" 555,="" each="" is="" only="" going="" be="" half-full.="" also,="" colors="" are="" diced="" up="" from="" 2="" bytes,="" rather="" than="" 4.="" so="" might="" do="" something="" like="" this="" your="" inner="" loop:
short*="" curcolor;
byte="" r,="" g,="" b,="" avg;
="" ...
curcolor="*(pixel);
b" =="" (curcolor="" &="" 0x1f);
g="((curColor">>5) & 0x1F);
r = ((curColor>>10) & 0x1F);
a = ((curColor>>15) & 0x1);
// Expand color components to 8bit, then average here.
// Several ways to do this, more complicated than I
// can write in a couple minutes.
r = g = b = avg;
a = 1;
// Reduce color components to 5bit...
curColor = 0;
curColor = (short)((a<<15) & (r<<10) & (g<<5) & (b));
*(pixel) = curColor;
pixel++;
Using pointers like this is significantly faster than using GetPixel/SetPixel, and its pretty strait forward code (You'll need to look up the reduction/expansion code for converting 16bit 555 color to 32bit color. There are plenty of resources on the internet with the info. I'd write it myself, but I have limited time.) Hope this helps, and I hope it was Grayscale you were after. Reduction to true B/W (two color, not 256 shades of gray) is a bit more complicated.
|
|
|
|
|
Hello all,
Thanx to all replyers.
I trying to figure out how to use these wonderful DirectShow Demo projects on this site to create a converter from 32bit color depth to 16 bit in C#.
Is it possible?
I`ve learned that graphBuilder2 will always fix the graph as he wants.
Can someone help with a graph code that converts 32bit video to 16bit color depth?.
Many thanx.
|
|
|
|
|
(I'm using C# 2.0)
Hi,
I have placed an icon file in resources.resx. The problem is that I don't know how to retrieve it.
In VB.NET 2.0, My.Resources.MyIcon does the trick, but what's the C# equivalent? Unfortunately, what happens under the hood with the My namespace is not well documented. Reflector on Microsoft.VisualBasic.dll didn't help either.
Can anyone help me on this? Here's my code:
protected System.Drawing.Icon GetIcon()
{
Assembly a = Assembly.GetCallingAssembly();
Stream stream = null;
Icon icon = null;
try
{
stream = a.GetManifestResourceStream("MyIcon.ico");
icon = new Icon(stream);
return icon;
}
catch {
return null;
|
|
|
|
|
Well, there are two kinds of resources for a .NET project. There are manifest resources, and compiled resources. A manifest resource is something you would include in your project, like a .ico file, and mark as "Embedded Resource". That marks the resource as being directly embedded into the .NET programs manifest.
There are also resources that are compiled into a single resource file, and that file is then embedded into the .exe. Your <filename>.resx file, under your form, is not the actual resource file. If you have a form, Form1.cs, that form also has a Form1.resx file. All resources for the form are stored in the .resx file. When you compile your project, that resx file is converted into a .resources file (look in your .\obj\ folder to find it after compile). The final step in compilation is to link or embed a .resources file into the .exe. Its also possible to create other .resx files, each of which will be compiled and embedded into the .exe when you compile the project.
Manifest resources can be accessed using the code you posted, but resources from a .resx file are different. You can not access them directly from the assembly, and must use a ResourceManager to do the job. Check out the System.Resources namespace (I think its the same for .NET 2.0 as for 1.1), and learn how to use the ResourceManager, ResourceSet, and ResourceReader classes. Using those, you should be able to access the resources that were generated from your resources.resx file.
|
|
|
|
|
This is the simplest way to retrieve resources from a linked resource if you are using neutral culture.
This example shows you how to retrieve strings, icons & images (any bin file can be retrieved), this example asumes that you have strings, icons & images in your resource file:
using System.Drawing;
using System.Resources;
using System.Reflection;
class MyClass
{
private ResourceManager rm = new ResourceManager "MyResourcefilenamewithnoextension",Assembly.GetExecutingAssembly());
public string GetString(string key)
{
return rm.GetString(key);
}
public Icon GetIcon(string key)
{
return (Icon)rm.GetObject("MyIcon.ico");
}
public Image GetImage(string key)
{
return (Image)rm.GetObject("MyImage.png");
}
}
Hope this little code helps you.
|
|
|
|
|
This code was very helpful, thank you!
|
|
|
|
|
There're type errors and the forum doesn't allow me to modify the post:
1) a "(" is missing when creating an instance of ResourceManager.
2) In method GetImage "MyImage.png" should be key.
3) In method GetIcon "MyIcon.ico" should be key.
I'm glad to help.
|
|
|
|
|
Am I missing something about how Visual Studio works?
Page_Unload is executed the first time that I open a page. Is this designed to be this way?
I thought that by its name, this method would be executed when the server removes the page from memory...not loading the page into memory. And, "yes" I can already see something of a conflict within my own statement. The Page_Unload method must be read into memory before the server can run it...but, that does not imply it should execute...does it?
Any commentary to improve my understanding would be appreciated.
Thanks.
SD
|
|
|
|
|
I always thought "Load" and "Unload" where bad terms for web app API in this situation. In this case it should have been "Pre"/"Post" or some other pair of terms I'm drawing a blank on. The idea is that when the server touches the object for some activity it fires a "Load" and when it is done with it it fires a "Unload". The action that triggered the pair of events may not have anything to do with actual Html or sending data to the client. The object itself has a "lifetime" outside of these pair of events as well (the object might be created hours before the actual event, the object might not be disposed for hours).
Ultimately, having web controls behave this way is desirable over being tied to create/destroy events.
-- modified at 10:40 Friday 30th September, 2005
|
|
|
|
|
Tom,
the flood lights just went on. Thanks for the terminology seperation, too. Page_Unload is not what I needed at all.
Best Regards,
William
|
|
|
|
|
Hi everybody...
I have crystal report 9.x for VS.NET installed with my VS.NET 2003 installation CD.I want to create dynamic reports at runtime with crystal reports. I searched in google and found that, it needs RAS (Report application Server) of crystal report that is not contained in VS.NET 2003 installation CD.Please tell me where I can download it from the web ?
Best Regards,
Xironix
[ _ Always there is another way _ ]
|
|
|
|
|
hi,
i have am retrieveing data from file and populating dataset and now i have to search some data, i dont want to treverse all the tables as it is heavy for processor
is it possible to run a sql query that can fetch my desired value from dataset, if not possible in dataset what control should i use from which i can fetrch data using sql query
Waiting for your help
Regards
Arus
|
|
|
|
|
On a dataTable you can set a rowFilter something like - ds.Tables[0].DefaultView.RowFilter = "name like 'a%'" So maybe check out those properties as well as the DefaultViewManager property of a DataSet - I think that one might be the one to use.
|
|
|
|
|
You can not run SQL queries directly on any ADO.NET data container (DataTable, DataView, DataSet). Your currently only able to set filters (i.e., the where clause of the SQL statement) or sorts (i.e., the order by clause of the SQL statement). If filtering and sorting is all you need, your good to go, although I must warn you, they can be quite slow. The DataSet is going to do all the work you would have done to find the records you needed, and its going to go through more code than you would write yourself most probably.
If you have 5000 rows in your datatable, and you sort them with ADO.NET, its going to be noticably slower than if you sorted them on a database server with a SQL query. The DataSet object also has a significant amount of overhead to provide all the capabilities it offers, so sorting with a DataSet may even be noticably slower than if you sorted manually.
For your purposes, you might be best off writing your own code to find the data you need, or else dump the data into a true database somewhere and actually run that SQL query.
|
|
|
|
|
I need to be able to rotate an image kinda like a parking break found inside of a car. It needs to rotate on its far left axis and move from 0 to say 45 degrees. Any help would be much appreciated. Thanks in advance.
P
|
|
|
|
|
|
how to pass messages between java and .net without using sockets
Mohamed Hasan is usally called as Hasan. He is very much interested in C++ programming . He slowly picking up .NET programming. He done his Bachler degree in Arumugam Pillai Seethai Ammal college Thiruppathur. and Master degree in MK university College.
Contact him at: hasansheik@hotmail.com
hasansheik@yahoo.co.in
hasansheik@lycos.com
|
|
|
|
|
string value="hasan";
Btn_save.Attributes.Add("OnClick","clientfun('"+hasan+"')");
the above methed u well pass value server to client side javascript;
----------------
client side/javascript u can access the value following methed
function clientfun(element)
{
var str=element;
alert(str)
}
|
|
|
|
|
|