|
Hi Greg,
I think you could use this code ( for little endian) :
int result = 0;
int limit = 4;
static float GetFloat(byte[] ToArray, int startindex)
{
for (int i=0; i <limit; i++)
{
byte thebyte = ToArray[startindex +limit-i-1];
result = result << 8;
result = result | thebyte;
}
return result;
}
I didn't manage binaries numbers wrote using big endian over little endian , but i think they are opposite in writing mode.
Try this, If it doesn't work change [startindex +limit-i-1] to [startindex +i]
hope this help you.
|
|
|
|
|
FYI, 0x0000068B is the int32 representation of 1675, not float. Also, if you're using the BinaryReader class, why not just use the ReadInt32, ReadSingle, etc. methods? Will they not work when you specify the endian-ness of the file?
Dybs
|
|
|
|
|
Hi to all,
I have a problem with a monochrome printer. ( samnung SCX-4x21 series)
I have a program that write a report on a printer. ( the content of the report consist of colored text and graphic objects ; I mean plain text, lines, rectangles , images..)
The problem is when I print the report on a monochrome printer. In this case for the objects with a black property color the rendering to the printer is ok , but for the objects with colored property the rendering to the printer is wrong. What is printed is a dirty gray color with wrong grain points.
I thought by myself that a monochrome printer translate a colored page content in a monochrome color automatically. doesn't it steel true? or am I wrong something?.
My snippet code is :
...
Printer = new System.Drawing.Printing.PrintDocument();
Printer.BeginPrint += new PrintEventHandler(doc_BeginPrint);
Printer.PrintPage += new PrintPageEventHandler(doc_PrintPage);
Printer.EndPrint += new PrintEventHandler(doc_EndPrint);
PrintController standard = new StandardPrintController();
Printer.PrintController = standard;
void doc_BeginPrint(object sender, PrintEventArgs e)
{
Printer.PrinterSettings.DefaultPageSettings.Color = false;
}
void doc_EndPrint(object sender, PrintEventArgs e)
{
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
Pen ePen = new System.Drawing.Pen(Color.Orange, 1);
Font eFont = new System.Drawing.Font("Tahoma",08,FontStyle.Regular);
SolidBrush eBrush = new SolidBrush(Color.Red);
e.Graphics.DrawRectangle(FCanvasPen, e.MarginBounds.X, e.MarginBounds.Y, e.MarginBounds.Width, e.MarginBounds.Height);
e.Graphics.DrawString("some text", eFont , eBrush , 220, 50);
eFont.Dispose();
eBrush.Dispose();
ePen.Dispose();
e.HasMorePages = false;
}
Probably is a stupid question, but i can't get rid of.
Could someone help me to solve
|
|
|
|
|
If you know in advance that a monochrome printer is being used (e.g. user presses a button 'Print in Monochrome', or similar), you might be able to use a boolean field and convert the colors to greyscale. Something like:
if (monochrome)
{
Pen ePen = new System.Drawing.Pen(ConvertToGreyscale(Color.Orange), 1);
}
else
{
Pen ePen = new System.Drawing.Pen(Color.Orange, 1);
}
Font eFont = new System.Drawing.Font("Tahoma",08,FontStyle.Regular);
if (monochrome)
{
SolidBrush eBrush = new SolidBrush(Color.Red);
}
else
{
SolidBrush eBrush = new SolidBrush(ConvertToGreyscale(Color.Red));
}
For the ConvertToGreyscale Method Google for convert to greyscale c# there are so many different ways to do this, that you are better off choosing for yourself.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
thanks Henry,
As I say in my post , I didn't know I must do it by hand. My knowledge is so poor?.
In any case, the only information I know is this flag in PrintDocument object:
( Printer.PrinterSettings.SupportsColor ).
When I tried to check this flag I got the contrary of the true; I mean , in a printer that support color I receive this flag false and vice versa. I am confused!
Do you confirm me this is the right direction ?
thanks
|
|
|
|
|
Have you looked at the MSDN documentation for PrinterSettings.SupportsColor? There is an example there that prints 2 pages, only the first in color. If this works for your printer, then you have the solution.
I had assumed that you had exhausted, all possibilities and that is why I suggested what I did, as if you had then there must be a peculiarity with your printer which my code might have overcome. I would suggest that you investigate the MSDN documentation further, and experiment with the examples you find there. You will learn more by doing that, than by asking on here.
If you do get stuck, by all means come back yo CP and ask a new question.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you Henry,
Generally I don't like to get information on MSDN , because most times my ideas are clear when I get in to, and confused after I read the items that explain what they want and not what you are looking for.
I said "most times" , but not all times. Probably this time is right time. ( I hope!)
Thanks again.
|
|
|
|
|
I need to place some text rotated at 45 degrees onto a bitmap. The text needs to be centred on a specific point. Placing normal text centred on a point on a bitmap is easy enough, and I’ve googled a number of different solutions to rotating text ... but I can’t rotate *and* centre on a point at the same time. An added complication is the text may sometimes contain CRLFs.
Can anyone show me the code how to do this (in VS2005)? Thanks.
|
|
|
|
|
Hi,
this is my view on this:
1. first attempt to paint the text without rotation; the text height can be measured using Graphics.MeasureString; when given the available width it will optionally do word wrapping, and anyway it will calculate the effective width and necessary height. So you know the distance from topleft to center now.
2. you can ask a Graphics to do all transformations for you; first order a translation to the point where your text should be centered; then order a rotation; now draw the string with Graphics.DrawString at location (0,0). That should do it.
|
|
|
|
|
Hi Luc
Sorry to sound like a newbie but can you give me the code to show how this is done? I tried but got myself muddled.
|
|
|
|
|
No, sorry, I am not going to create and provide code. That is not how this site works. You do the effort, show some results, then ask specific questions.
So I suggest you raise the level of your knowledge where it is lacking by studying serious material (preferably a book) and/or performing some experiments.
Hint: when playing with TranslateTransform and RotateTransform, make sure to make your view much larger than you consider necessary, things go out of sight pretty soon, especially if you choose the wrong polarity for some of the factors.
|
|
|
|
|
Hello,
i have no problem to start a presentation by an c#-program (interop), but i need to navigate to slides by an externel source (via serial-interface).
Is there a way to "call" a special slide via PowerPoint-automation?
Heiko
|
|
|
|
|
I'm running a little code that should write code to a text file within the application directory, however I'm getting the following error:
Access to the path c:\inetpub\wwwroot\MapFile\Mapped.txt is denied
I'm logged on as Administrator on Windows Server 2008 and running VS 2008 SP1 / .NET 3.5.
Any ideas?
Jon
|
|
|
|
|
Navigate to that folder, view the properties -> security. Give Users write permissions.
|
|
|
|
|
This can also come up if the file has already been opened somewhere else in your code and you've forgotten to close it.
|
|
|
|
|
If this is an ASP.NET application, the accout you're using to run this code under the debugger doesn't matter. It's actually running under the ASPNET account, which IIRC, by default, does not have Write permissions to the application folder. In order to make this work, and I do NOT recommend this, you have to give the ASPNET account Write permissions to the C:\inetpub\www\MapFile folder.
|
|
|
|
|
Yeah I thought so, but what is the ASP.net acct used? When checking the users on the OS there were none other than the Administrator and another one created by sql server.
This is not a production environment, so I'm not worried about security, but it's good to know.
Jon
|
|
|
|
|
jon_80 wrote: but what is the ASP.net acct used?
Depends on the server being used. If it's the development web server that comes with Visual Studio, it's "ASPNET". If it's IIS 6.0 and below, it'll probably be something like "IUSR_machineName". For IIS 7.0 and above, I think this name got changed to just "IUSR".
|
|
|
|
|
This method should work for you.
public static void AddFileSecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
try
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = fInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
// Set the new access settings.
fInfo.SetAccessControl(fSecurity);
}
catch (Exception exp)
{
Console.WriteLine(exp.Message.ToString());
Console.Read();
}
}
You can use it with something like this:
FileWritePermission.AddFileSecurity(path, "everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
Cheers
|
|
|
|
|
Cute code, but an account (and core running under that account) cannot grant more permissions to itself, nor anyone else, than it already has.
|
|
|
|
|
Good morning everybody,
I would like to show stocked data in ListView to send DataTable aprés Select. DataTable contains a colonne of type Byte [] Array, I do not succeed show pictures in gate.somebody address can help me SVP?
|
|
|
|
|
I think that I understand what you want to do. If I am right, this[^] link should help you.
If I am wrong, please edit your original post and try to explain you problem more clearly.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Good morning,
Excuse me, I am French, I speak the language badly Englishman. My question is the following:
I have one banks on look at foundation of data which contains columns Name, Forename, Photograph
I make a request SQL which is the following:
cmd.CommandText ="SELECT NAME, FIRSTNAME, PHOTO FROM USER";
I fill ListView in the following way:
sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = cmd;
try
{
sqlDa.Fill(dt_ListeUtilisateur);
if (dt_ListeUtilisateur.Rows.Count &gt; 0)
{
lstUtilisateur.DataContext = dt_ListeUtilisateur.DefaultView;
}} //lstUtilisateur = ListView
XAML :
<listview margin="7,10,15,48" name="lstUtilisateur" itemssource="{Binding}" borderbrush="{x:Null}" listboxitem.selected="lstUtilisateur_Selected" selectionchanged="lstUtilisateur_SelectionChanged">
<listview.view>
<gridview>
<gridviewcolumn header="NAME" displaymemberbinding="{Binding Path=NAME}" selector.isselected="True">
<gridviewcolumn header="FIRSTNAME" displaymemberbinding="{Binding Path=FIRSTNAME}">
<gridviewcolumn header="Picture" width="100" displaymemberbinding="{Binding Path=MyImage}">
<gridviewcolumn.celltemplate>
<datatemplate>
In the column Picture of my ListView, I have unfortunately not the photograph but Byte [] Array you can help me please.
|
|
|
|
|
Good morning,
Excuse me, I am French, I speak the language badly Englishman. My question is the following:
I have one banks on look at foundation of data which contains columns Name, Forename, Photograph
I make a request SQL which is the following:
cmd.CommandText ="SELECT NAME, FIRSTNAME, PHOTO FROM USER";
I fill ListView in the following way:
sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = cmd;
try
{
sqlDa.Fill(dt_ListeUtilisateur);
if (dt_ListeUtilisateur.Rows.Count>0)
{
lstUtilisateur.DataContext = dt_ListeUtilisateur.DefaultView;
}} //lstUtilisateur = ListView
XAML :
<listview margin="7,10,15,48" name="lstUtilisateur" itemssource="{Binding}" borderbrush="{x:Null}" listboxitem.selected="lstUtilisateur_Selected" selectionchanged="lstUtilisateur_SelectionChanged">
<listview.view>
<gridview>
<gridviewcolumn header="NAME" displaymemberbinding="{Binding Path=NAME}" selector.isselected="True">
<gridviewcolumn header="FIRSTNAME" displaymemberbinding="{Binding Path=FIRSTNAME}">
<gridviewcolumn header="Picture" width="100" displaymemberbinding="{Binding Path=MyImage}">
<gridviewcolumn.celltemplate>
<datatemplate>
In the column Picture of my ListView, I have unfortunately not the photograph but Byte [] Array you can help me please.
|
|
|
|
|
Your English is quite good. Part of what you are trying to do, is what I thought from your first post, so it must be reasonable.
I must admit that I didn't read all of the link I gave, but I thought that it dealt with reading and saving images to and from a database. If that is not where your problem is, then can I suggest that you post in the WPF forum here on CP, as your application would seem to be a WPF one.
If loading the photo is your problem, then perhaps you might like to Google for yourself. The search term I used was 'Loading Image from SQLServer C#', to see if there is anything more appropriate.
You seem to be slightly annoyed by my suggesting that you re-word your question. You shouldn't be, I often find that trying to ask something using different words makes me understand it a little better, myself.
Anyway, Good Luck! (Bon chance ????)
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|