|
You can save the image to a System.IO.MemoryStream , which does have the elusive ToArray method.
Charlie
if(!curlies){ return; }
|
|
|
|
|
This should do the trick
public static byte[] GenerateImageBytes(Bitmap bm)
{
byte[] bytes = null;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bm.Save(ms, ImageFormat.Gif);
bytes = ms.ToArray();
ms.Close();
return bytes;
}
Thomas
|
|
|
|
|
Or, with slightly more pleasant syntax, with better resource management:
public static byte[] GenerateImageBytes(Bitmap bm)
{
using(MemoryStream ms = new MemoryStream())
{
bm.Save(ms, ImageFormat.Gif);
return ms.ToArray();
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Yes, this looks greate
But, will the MemoryStream be closed (ms.Close())?
|
|
|
|
|
That's what the using statement is for. The using clause automatically disposes of any IDisposable objects, including MemoryStream, thus it will call the appropriate close method when the scope leaves the using clause.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Hi folks!
I'm being bugged by a very nasty problem and don't know how to proceed any further, perhaps someone can enlighten me.
In my programs I need an RSACryptoServiceProvider to encrypt and decrypt stuff. In order to check whether this is possible during startup, I simply try instantiating the CSP. If this blows, the user is told to install the latest service packs, IE5.5+ or anything that usually includes the strong encryption CSPs.
The code to do this is
CspParameters param = new CspParameters();
param.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider csp = new RSACryptoServiceProvider(param); so I'm already using the Machine Key Store.
This throws an exception (CryptographicException: CryptoAPI cryptographic service provider (CSP) for this implementation could not be acquired), if the application was installed by an administrator on a Win2K SP4 machine and is then run by a user with restricted rights (belonging to group "Users").
When the admin is running the application, the code above executes flawlessly AND afterwards, the restricted user also can run the program!
I've been searching for this problem for quite some time and only found reports where this exception is thrown in an ASP.NET context, but my applications are Windows Forms applications, not ASP.NET ones.
I can't find which additional rights the user has to have for the code to work before the administrator has at least run it once.
Giving full access to C:\documents and settings\all users\application data\microsoft\crypto\* didn't help.
I'm completely at a loss on what to do next.
Can anyone help?
TIA,
mav
|
|
|
|
|
You may try to set the RSACryptoServiceProvider.UseMachineKeyStore Property to false so that the key could be persisted in the user profile store instead of the computer's key store. Try if it can work while not defeating the purpose of your application.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
Hi Ashok!
Thanks for your suggestion, but I had this configuration before switching to MachineKeyStore and it didn't work either.
Thanks nevertheless,
mav
|
|
|
|
|
In one of my projects, I had used the following flag:
param.Flags = CspProviderFlags.UseDefaultKeyContainer;
instead of using the
param.Flags = CspProviderFlags.UseMachineKeyStore;
Thereafter, instead of storing the key in the Machine Key Store, I had hard-coded the key in my code. Of course, in the version released for outside world, I did not store my private key in the code. But, in a separate version meant for me only, I used the private key (which I used to pre-encrypt certain strings).
For storing the key in the hard-coded form, I used format like this (key not shown here):
string publicKeyXML = @" -------- ";
rsa.FromXmlString(publicKeyXML);
Thereafter, I could easily access the key for any user (whether administrator or otherwise).
I wonder whether a scheme like this could fit in your requirements.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
Thanks again for your suggestion.
But meanwhile I found the reason: In addition to what the documentation says (users must have access to %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA to be able to create the MachineKeys directory), the very first time the additional directory MachineKeys has to be created in %SystemRoot%\System32\Microsoft\Crypto\RSA as well!
Once this directory exists, everything works as expected, but a regular user isn't allowed to modify System32 and because the CSP seems to be depending on the existence of the directory it rolls over and dies with a meaningless error message!
I found this out with the help of RegMon and FileMon by Sysinternals, after running through hundreds (literally hundreds!) of file and registry access events.
Nevertheless, the problem seems to be solved.
Thanks for your support,
mav
|
|
|
|
|
Hello all,
I am currently trying to convert a batch (CSC) compiled project into a VS 2003 solution, and I seem to be having a small problem with embedded resources.
This particular project uses the following batch arguments to compile (which works fine btw)
@echo off
if not exist lib md lib
if not exist doc md doc
if exist lib\Novell.Directory.Ldap.dll del lib\Novell.Directory.Ldap.dll
echo "Building resources..."
resgen Novell.Directory.Ldap\Novell.Directory.Ldap.UtilClass\ResultCodeMessages.txt lib\ResultCodeMessages.resources
resgen Novell.Directory.Ldap\Novell.Directory.Ldap.UtilClass\ExceptionMessages.txt lib\ExceptionMessages.resources
echo "Generating lib\Novell.Directory.Ldap.dll.."
csc /noconfig /w:1 /r:System.dll /target:library /resource:lib\ResultCodeMessages.resources
-> /resource:lib\ExceptionMessages.resources /doc:doc\comments.xml
-> /out:lib\Novell.Directory.Ldap.dll /recurse:Novell.Directory.Ldap\*.cs
del lib\ResultCodeMessages.resources
del lib\ExceptionMessages.resources
The problem I have is with the two resources generated above using the resgen tool. In my VS solution I have set both these files to be "embedded resources" but I get the following exception
{"Could not find any resources appropriate for the specified culture (or the neutral culture)
in the given assembly. Make sure \"ResultCodeMessages.resources\" was correctly embedded or
linked into assembly \"LibLdap\".\r\nbaseName: ResultCodeMessages locationInfo: <null>
resource file name: ResultCodeMessages.resources assembly: LibLdap, Version=2.1.3.0,
culture=neutral, PublicKeyToken=null" }
When the following code is executed:
defaultResultCodes = new ResourceManager("ResultCodeMessages", Assembly.GetExecutingAssembly());
result = defaultResultCodes.GetString(Convert.ToString(code), defaultLocale);
A similar exception occurs when attempting to access the other resource.
I know this is simply that the code cannot find the resource, can anybody tell me how to embed it correctly?
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
-- modified at 8:19 Thursday 8th September, 2005
|
|
|
|
|
How to do it that include a exe file In a project? I have some method in a exe file.but I want to use them in another project.Can do ti? How to do it?
|
|
|
|
|
hi there,
u cannot include an exe file as reference an dll. But u can reuse methods in exe file by executing it from ur application
<< >>
|
|
|
|
|
In .NET, you can reference .exe files just like you do with .dll files.
|
|
|
|
|
But you have to note that you can't add the reference with VS.NET, as only DLLs are selectable as assembly references.
But if you simply rename the EXE to DLL, it can be referenced without problems.
Regards,
mav
|
|
|
|
|
Hi
I want to make a windows application conditional in following way:
If I start the application without parameters, then it should start as a windows application
If I start it with parameters, it should run as a console application.
Currently I solved it by creating a console application and check the input parameters. If no parameters are given, it starts a windows.forms class. This works perfectly - almost.
The problem is, that if it runs as a windows application, it starts also a dos box, which I would like to have prevented. Now the question is: How can I start the windows application conditional without the dos box?
Thanks Fredy
|
|
|
|
|
One simple solution may be like this:
1. Make a skelton wrapper application (which should preferrably be a console application), which should have a very simple main method to call or execute the relevant application.
2. So, in the wrapper application's main method, check for parameters and start the windows application or the console application, as the case may be.
3. Immediately after the second step, the skelton wrapper application may exit.
Although there may be some better methods, but this simple solution may work too.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
|
i've made a simple (System, IO, Collection) console .exe and given to a friend has Windows XP Home.
if he tries to run gets a runtime error.
why?
|
|
|
|
|
Sasuko wrote:
i've made a simple (System, IO, Collection) console .exe and given to a friend has Windows XP Home.
if he tries to run gets a runtime error.
why?
What is the runtime error message?
Does the XP home machine have the same version of the .NET framework as your application is compiled against?
Michael
CP Blog [^] Development Blog [^]
|
|
|
|
|
no, he hasn't any version of the .NET framework.
I thought for console applications it wasn't need but just for windows application.
Do i need to create a setup solution so... isn't it?
Anyway how can i add to my setup solution the newest framework?
|
|
|
|
|
Without the .NET framework, a .NET application will not work on a machine. Your setup program can ask a user to download .NET framework (1.1) from Microsoft site from address http://www.microsoft.com/downloads/details.aspx?FamilyID=262D25E3-F589-4842-8157-034D1E7CF3A3&displaylang=en[^] if it is not found on his machine.
Adding the redistributable .NET framework in your setup itself is not advisable due to its size of about 22 MB. But, if you have to consider it, then in your setup project in the VS-IDE, under the "Detected Dependencies" node, find the "dotnetfxredist_x86.msm" entry. Right-click on this and remove the check-mark from the "Exclude" property. It should do the trick and the .NET framework may get included in your setup project.
Regards,
Ashok Dhamija
_____________________________
Padam Technologies
|
|
|
|
|
hi there ,
i have a C# Form in VS.Net and i am working whit Sql DB now i have datagrid on my Form
i want to see all the orders From date 1 to date 2
Sample :
show me all the orders from : 01/09/05 to 09/09/05
and i all geeting the data and everything is fine.
whan i want to print this report iall get all of the orders beetwen the 2 dates .
i want to see also the dates that i typed in the Form how can i do it ?
in the opper report i want to see it like that
this is the orders beetween 01/09/05 to 09/09/05
how can i pass this dates from the Form to the report ?
thanks aloot....
|
|
|
|
|
I have a class with two integer properties.
An array of this type is assigned to a DataGrid as DataSource.
I have a Hashtable, which contains the textual representation of the integer properties of the previous array.
How can I make grid to show these textual values instead of numbers if the first array is assigned as DataSource?
-- example:
<br />
public class Book<br />
{<br />
private int bookID;<br />
private int amount;<br />
<br />
public int BookID { get { return this.bookID; } }<br />
public int Amount { get { return this.amount; } }<br />
}<br />
<br />
<br />
private void InitGrid()<br />
{<br />
Book[] books;
books = GetBooks();
<br />
Hashtable bookTitles = new Hashtable();<br />
bookTitles.Add(17, "Jungle Book");<br />
bookTitles.Add(38, "Another Book");<br />
<br />
this.dataGrid1.DataSource = books;<br />
<br />
}<br />
|
|
|
|
|
Well Dear!
i have a problem. i have to set the scren resolution ,monitor refresh rate of three monitors(Dual Display) @ same time with win xp sp2 in c#. I m using a Win32 API function EnumDisplay Settings to get all the display modes that the VGA cards support then i Call ChangeDispaySettings API function to change the resolution . but when i change all monitors display to one resolution any one of them flickers may be due to refresh rate settings. i want to know how to select the best display setting and refresh rate programatically so as my screen doesnt flicker without restarting the system. waiting reply anxiously
I M new in .net p
|
|
|
|