|
Hi David,
I am puzzled with the code shown as I am unfamiliar with most of what is used there.
Maybe you are close to a solution, maybe you are way off, I can't tell.
One detail remark: I don't see how you cou;d pass a Rectangle where a RectangleF is expected.
I assume it is all about getting an RTB draw at a different resolution.
I would tackle that completely differently, by manipulating the RichText itself.
That I have done in the past, to a limited extent.
With an adapted RTF, you could then have a regular (maybe hidden, probably differently sized) RTB render everything, and use its DrawToBitmap method to easily get the resulting bitmap.
Although not strictly necessary in theory, it may help if you could provide numeric values (e.g. I still don't know your printer resolution), an image of a typical label, an indication of how complex and how constant the content/layout is, a sample of the RichText (maybe better mail than publish that).
Is there a viewscale command present in the RTF?
How is the RTF generated in the first place?
|
|
|
|
|
Hi Luc,
All good points.
You are right about the rectangle. I added the remarks so that you could more see what coordinates is supposed to be passed in. That is all handled by other methods Typo - sorry, should have read taken more care and yes, it is supposed to be a RectangleF.
I think I am now close to a solution. After spending all day on it, the light went off in the head and I now think I understand what I am doing. Partly in thanks to your previous posts.
I am working on increasing the rtf (same as you have suggested) by manipulating it directly. The edit box provides a handle to push the output into a DC. I have the edit box into a loop getting setting edit.SelectionStart=i , edit.SelectionLength=1 and increasing the edit.SelectionFont by an as yet undetermined factor. Everything else will be an adaption of more or less the like the sample code you kindly provided yesterday. I will look into the viewscale command. I am still finding my way around C# a bit.
The office laser printer is 600dpi. The Label printer is 191dpi or 203dpi depending on model. The labels themselves are those 2*3 inch or so labels you find stuck onto packets of fresh meat and the like and can be fairly simple to quite complex depending on whether they contain a barcode, Useby dates, net weights various descriptions in various sizes of the product, contents and tags. The differing label elements have their own methods and looked good when printed directly to the printer DC. But then the device contexts used in the rich text stuffed it all up. Even then I was totally oblivious to the pixelation problems until I finally started testing on the label printer. On the Laser, they were not perfect, but were good enough to put on a salable item. Out of the label printer, they look like someone just used a fine felt tip pen and dotted all the numbers.
The RTF is generated in our backoffice program and loaded into the scales database using a WYSIWYG'ish editor. It is proper RTF (open-able in wordpad) it that is what you wanted to know.
-David.
|
|
|
|
|
OK, the picture is getting clearer now. Thanks.
I am not sure about the viewscale command, I just browsed through the RTF specification looking for some general scaling command, I haven't actually used it.
FYI: RTF is just plain text, you can deal with it outside a RichTextBox and outside Word/Wordpad,
just read the text file as text (Notepad can do that), it is all ASCII, mostly commands, lots of backslashes, and pretty complex. One of the nice things is all font families to be used must be listed at the beginning of the RTF, and all font sizes are set with an \fs command where the parameter is in half-points.
Editing the fs commands may be easier and certainly lots faster than iterating through an RTF by selecting each individual letter rendered (which might result in a much larger file too).
You can take the RTF from RichTextBox.Rtf then modify it and assign it again to RTB.Rtf
Here is a - rather weird - idea that should work and may provide an emergency solution or not be acceptable at all:
- connect a second monitor to your PC, size does not matter much
- set its resolution to 200 dpi (you can choose what Windows thinks the resolution of a monitor is,
it always starts at a default of 96dpi although a lot of monitors nowadays are 120 dpi; it is
hidden in "Display Settings" under a couple of "Advanced" buttons and probably works in percents,
relative to 96 dpi, so try 200% for starters; your setting will eventually be reflected in the
Graphics.Dpix/Dpiy of your screen (BTW: I know of no way to get them set differently))
since content is texts + bar code, no images, it does not have to be exact I guess.
- create/modify app showing a form on that "high-res" monitor with an RTB at correct label size
- text should show as good as it can get on the label printer
- use Control.DrawToBitmap to get the bitmap
|
|
|
|
|
I think I am going around in circles now. It is not any clear now than it was at lunch time.
|
|
|
|
|
That isn't really a question is it?
Can you mail me one label content (RTF file I guess)?
|
|
|
|
|
Hi David,
here is a little RTF text scaling routine, using simple stuff only (no regex!):
private string ScaleRtf(string text, double scale) {
log(text);
int lastPosition=-1;
for (; ; ) {
int i=text.IndexOf(@"\fs", lastPosition+1);
if (i<0) break;
lastPosition=i;
log("Found fs at "+i);
int fs=0;
for (i+=3; ; i++) {
char c=text[i];
int j="0123456789".IndexOf(c);
if (j<0) break;
fs=10*fs+j;
}
int newFs=ScaleUp(fs, scale);
text=text.Substring(0, lastPosition)+@"\fs"+newFs.ToString()+text.Substring(i);
log(text);
}
return text;
}
private int ScaleUp(int fs, double scale) {
return (int)(fs*scale+0.5);
}
private void log(string s) { }
|
|
|
|
|
This is really super urgent. I wont be going home tonight until this is done. It is already knock of time here!!
If anyone else would like to chime in, please do so. I am sure this like the previous is something simple, but there seems to be too many combinations and I have already been at this all day.
Kind regards,
David.
|
|
|
|
|
With ScriptErrorsSuppressed set to true the display of javascript error dialogs is eliminated. However, this setting results in the blocking of access to all sites that have any kind of certificate issues. With the setting true, the control displays a warning instead of the requested page and it is not possible to move away from it, even though there is supposedly a link to do so. At least, this is what happens for me.
With ScriptErrorsSuppressed set to false, a warning dialog appears, and then the site is accessible. However, any javascript errors will generate the error dialogs.
Seems to me these are two different issues being covered with a single setting.
Any ideas on how one can access these sites with "certificate issues", ideally without the warning dialog, while keeping the ScriptErrorSuppressed set to true with the WebBrowser control?
thanks
|
|
|
|
|
Is there any problem with Cosmos Milestone 3? because i cant compile it and i get the error msg saying that a method is missing.
|
|
|
|
|
Do they not have a forum ? That seems to be the place to go to talk to people who will all know what you're asking about.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I am working on a method to convert time, 00:00 to a double 00.00, and separate the minutes from the time to calculate elapsed time. I have two methods, but am getting a 'Invalid rank specifier: expected',' or ']' error.
Hope this is not too long, please help.
class TimeConversion
{
static void Main(string[] args)
{
string time = "00:00";
double hours = TimeSpan.Parse(time).TotalHours;
double minutes = TimeSpan.Parse(time).TotalMinutes;
string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"};
//return timeArray;
Convert.ToDecimal(timeArray);
Console.WriteLine("8:17", "15:26", "18:32", "0:46", "10:38", "13:56");
Console.ReadKey();
}
static double ConvertTime(string clockIn, string clockOut)
{
string time = "00:00";
double hours = TimeSpan.Parse(time).TotalHours;
double minutes = TimeSpan.Parse(time).TotalMinutes;
double dminutes = Convert.ToDouble(minutes);
foreach (
if (dminutes >= .07)
dminutes = 0.00;
if (dminutes <= .22)
dminutes = 0.25;
if (dminutes <= .37)
dminutes = 0.50;
if (dminutes <= .53)
dminutes = 0.75;
if (dminutes > 53)
dminutes = 1.0;
return ConvertTime;
}
}
Thanks
OneTreeUp
|
|
|
|
|
New to C#?
There appear to be a number of problems in your code; which statement is causing the error you mention?
|
|
|
|
|
Yes, I am new to C#, the error is being created from the Main method:
string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"};
|
|
|
|
|
I don't understand exactly what your problem is? Do you want to convert hours and minutes to decimal hours, ie. 12:45 would be 12.75?
I have a couple of lines, which should work:
static void Main(string[] args)
{
string[] timeArray = new string[] { "8:17", "15:26", "18:32", "0:46", "10:38", "13:56" };
foreach (string str in timeArray)
{
TimeSpan span = TimeSpan.Parse(str);
Console.WriteLine(span.TotalHours.ToString("00.00"));
}
Console.ReadKey();
}
Good luck!
|
|
|
|
|
Thanks, that work, my problem was placing a value in the [], but the second method that I am trying to resolve is separating the minutes in order to calculate the time based on the criteria.
Time is based on minutes, for more than 7 minutes, no extra time, for more than 22 minutes, change to 0.25 (or 15 minutes). How can I add that to a for statement?
if (dminutes >= .07)
dminutes = 0.00;
if (dminutes <= .22)
dminutes = 0.25;
if (dminutes <= .37)
dminutes = 0.50;
if (dminutes <= .53)
dminutes = 0.75;
if (dminutes > 53)
dminutes = 1.0;
return ConvertTime;
|
|
|
|
|
like that?
static void Main(string[] args)
{
string[] timeArray = new string[] { "8:17", "15:26", "18:32", "0:46", "10:38", "13:56" };
foreach (string str in timeArray)
{
TimeSpan span = TimeSpan.Parse(str);
double dHours = span.TotalHours;
Console.Write(dHours.ToString("00.00") + " ");
dHours += GetExtraTime(span.Minutes);
Console.WriteLine(dHours.ToString("00.00"));
}
Console.ReadKey();
}
private static double GetExtraTime(int iMinutes)
{
if (iMinutes > 53)
return 1.0;
if (iMinutes > 37)
return 0.75;
if (iMinutes > 22)
return 0.5;
if (iMinutes > 7)
return 0.25;
return 0;
}
|
|
|
|
|
Hi all,
how can i change one of my forms properties in one other running thread?
i mean i have thread1 which form is made in and thread2 which is resetting some of it properties. but doing so, my form goes into 'not responding' state (by operating system) and i have to end the application. what is the solution? msdn couldn't help.
thanks
|
|
|
|
|
While you are waiting for someone to more completely answer your query, I would suggest that you research (MSDN and GOOGLE) the InvokeRequired property.
This is a fundamental part of the solution and there are examples aplenty, which should at least get you thinking in the right areas.
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
but it is not really going to work. my form again goes to 'not responding'. why?
modified on Tuesday, April 21, 2009 3:44 PM
|
|
|
|
|
I've constructed a very simple sample using a System.Timers.Timer as it runs on a seperate thread. You should be able to figure it out from this.
[Edit] Changed the sample code to show how to call a method with parameters. [/Edit]
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Timers.Timer timer;
public Form1()
{
InitializeComponent();
timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Start();
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.InvokeRequired)
{
BeginInvoke(new MethodInvoker(delegate() { UpdateText(sender, e); }));
}
else
{
UpdateText(sender, e);
}
}
private void UpdateText(object sender, System.Timers.ElapsedEventArgs e)
{
Text = e.SignalTime.ToString();
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Tuesday, April 21, 2009 4:50 PM
|
|
|
|
|
Hello Everyone-
I have been programming with C# building database applications for a year or so. I have a new side project that I am working on and quite frankly, I don't know where to start! (I can't even figure out what to type in to google!) What I am looking for is a starting point to get me going in the right direction.
I am trying to build an application that will utilize a camera, take a picture of a table with a predefined (green) background, and calculate the square footage of the piece of stone that is laid on it. Interfacing with the camera is no problem, I can tell the camera to snap pictures and access them.
I want to then open up this image that the camera took and analyze it. The table will be painted green (or white or orange). The stone will be laid on top, so for the sake of this message lets say its a piece of stone on a pure white table. I want to analyze that image and figure out the area (square footage) of that piece of stone. I know that I can do the mathematical calculations based on how far the away the camera is from the table, but I'm not sure how to open up an image and read that image, and tell the area of "space that is not white". If anyone could point me in the right direction I would really appreciate it!
Thanks so much in advance!
|
|
|
|
|
Take a look at Range Finder[^] article. recently published here on CP.
Find the range of the four corners, a bit of trig and Bob's your uncle.
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.”
|
|
|
|
|
First you have to figure out what format the picture was taken in. If it's RAW or BMP, then you've got nice little bytes of information for each rgb value of each pixel. If it was JPEG, then you've got to decompress it to get the pixel values.
I think it might help to search for the term "threshold" in regards to picture analysis. It is basically getting rid of the colors that you don't want.
Another way to find areas of the same color, since your data is basically a matrix, is to treat the column number as "x", treat the RGB value as "y", then find the change in y as x increases, along the row (aka a derivative). Then you've got an array of 0's for filled in areas of the same color, and enormous values at the border zones, and you can fill in your shape w/ whatever geometry you want to get the area.
Or, if this is a long term project, you could check out Activision Tools or Euresys E-Vision. They already do this all this and much more.
|
|
|
|
|
Here are my requirements:
1) A PDF viewer that is embedded in a window in my windows app.
2) I must be able to reference button_click events in the PDF from my windows app. (i.e. if i click a button in the PDF, the event occurs in my windows app.
Pertaining to the above requirements:
Here is what I've noticed so far. The Adobe Reader ActiveX works great at simply viewing PDF's and the buttons are shown too. However, I haven't found anything in the Reader library that allows me to reference the buttons in the PDF. This leaves the following questions.
Possible Solutions: (need your help/recommendations)
1) Can I use the Acrobat SDK to reference the document that is open inside my Adobe Reader ActiveX control? (If I can, then i can get a hold of my buttons and events). If I can do this, does anyone have any clue about the proper syntax? All of the the samples I've seen actually reference a document that acrobat opens, not the reader....
2) Can I embed the Adobe Acrobat (not the reader) in my windows app in order to view the files? I haven't seen this done yet. Every example I've seen opens the acrobat in it's own window!!!
3) Is there other software out there that offers both functionalities: 1) Embedded viewing window with 2) Full access to PDF library?
Any help in this matter would be greatly appreciated, as I have searched High, Low, and In Between for a solution.
Thanks,
jpc
|
|
|
|
|
Hi again,
I wonder if there is any possibility to accomplish the following:
A GUI has a button with attached eventhadler (button_click).
In this eventhandler, there shall be called a function, that gathers some information. The information iInfo shall be returned like
int iInfo = gatherSomeInfo();
to the eventhandler button_click in the GUI.
Here is the Problem: The gatherSomeInfo() function needs eventhandling to collect all information. So I have to leave the gatherSomeInfo() function before knowing what to return and loosing the ability to send the needed information back (as return value). It is not possible to collect all information and immediatly return from this gatherSomeInfo() function back to the eventhandler in the GUI.
The gatherSomeInfo() Function is hooked into another event (of another thread in fact) that finally signals the info. From that moment on I could send a return value but I don't know how.
The function call of gatherSomeInfo() within the button_click eventhandler would block the further execution (if waiting for return value) until the return is done but that would exactly be what I need for this procedure.
How can I do this??? I can't believe that there is no way to do that. Can anyone help please???
|
|
|
|
|