[Q] recognize letters in my app - Windows Phone 7 Software Development

hello,
I'm programming a WP7-App, i have a letter (for example the "A").
How can i recognize the input and match the correct character ?
sorry for my bad english

You can cast chars to ints.
see: http://www.asciitable.com/
In the table in that link, note that 'A' corresponds to a decimal number 65. When you cast your char 'A' to an int, it will turn into 65.
Similarly, (int)'a' is 97. And 'a' - ch, where ch = 'b', is equal to -1. Doing subtraction of chars automatically converts to integers. Casting the whole string to lowercase and then checking (currentChar - 'a' < 26) is a great way to check if you're looking at an alphabetic character (a through z).

Thanks for the answer...
the "A" is only an example caracter.
in the real world example i use japanese caracters.
the user shall be paint the correct caracter in my app, like this on the picture...

CB.NET said:
Thanks for the answer...
the "A" is only an example caracter.
in the real world example i use japanese caracters.
the user shall be paint the correct caracter in my app, like this on the picture...
Click to expand...
Click to collapse
That will be an insanely difficult task. Actually this in general takes years of study in order to accomplish
Handwriting recognition is one of the hardest things to accomplish.
If you do want to give it a shot, my suggestion:
Crop and rescale the images, and than determine patterns for each letter, thus an A can be build from 3 linear formules, check if the drawing matches this structure. You can than compute the derivatives of the drawings and from those derivatives cross check them with a database to determine which letter it is.
But this is extremely difficult, we tried to read digits in a sudoku puzzle which was already quite a difficult task to accomplish (and we tried to reference it against a database with images, as well as checking several characteristic points in a figure etc) this went OK with printed letters, but with handwritten it was a disaster. Not trying to discourage you, maybe there are libraries out there which you can use, but I would reconsider what you are trying to accomplish and determine an approach for yourself.

CB.NET said:
Thanks for the answer...
the "A" is only an example caracter.
in the real world example i use japanese caracters.
the user shall be paint the correct caracter in my app, like this on the picture...
Click to expand...
Click to collapse
I highly recommend making a class of "Cases" this way if it detects "A" it uses the "A" case select opposed to making a ton of "if" and "else" statements.
Better yet... You always could use an if/else statement or have an array of listed recognized items...
Here is something that might help: http://joshsmithonwpf.wordpress.com/2007/06/12/searching-for-items-in-a-listbox.

Related

Howto get started with SW development for Diamond

Hi all,
I must admit that I am completely new in the SW development for this kind of platforms. Therefore, I would like to ask you guys to direct me to a good way to start.
I have an application in mind that i would like to do it myself, and is for a personal application, so nothing to do with what is out... but it will involve the touch screen and it has to deal with a little database.
In other words, it would be like....
The main screen should be 9 squares (similar to a numeric keyboard), and pressing any one of those squares should pop/up a different screen with a list that correspond to that specific square (exactly how the calendar works).
There should be a secondary window to enter data to the list where I shoud associate every entry with an square.
This is basically all...
I have good experience programming C/C++... but not c sharp. So any document, example code, api, that you can provide is very welcome...
Thanks you all in advance...

Truetype fonts in evC++

Hi gents.
I want to ask you,how can I use external font loaded from ttf file in my app,developed under Embedded Visual C++?
I need to easily change color and size of the font and using the DrawText() function make an output into current DC.
Can someone make an example for me please?
Thank you.
Here's the bare bones of it ,you'll have to flesh it out to suit. It might not be perfect but it works.
Global Variable
Code:
HFONT g_hfont;
Forward declaration of EnumFontProc()
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData);
In WM_PAINT print it out. I'll use Wingdings. The name in the EnumFonts must match the actual name of the font as declared in the TTF file.
Code:
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
EnumFonts(hdc,TEXT("Wingdings"),(FONTENUMPROC) EnumFontsProc,NULL);
SelectObject(hdc,g_hfont);
DrawText(hdc,TEXT("12345"),5, &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
DeleteObject(g_hfont);
EndPaint(hWnd, &ps);
break;
In EnumFontsProc set the font to the first font given. Returning 0, ends the enumeration, non zero, give me the next.
To change the size do it here by changing lplf->lfHeight and lplf->lfWidth
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
g_hfont = CreateFontIndirect(lplf);
return 0;
}
To load and release your font add the code below to the message handling sections.
Code:
WM_CREATE:
AddFontResource(TEXT("\\Storage Card\\myfont.TTF"));
WM_DESTROY:
RemoveFontResource(TEXT("\\Storage Card\\myfont.TTF"));
Here's the proof it works, (with Wingdings anyway!)
Thanks man,I will try it ASAP.
Well,is it possible to read the ttf file directly from exe resource also?
I am still learning C++,so some things are a bit unclear for me. Can you please post this source?
This stuff is explained fully at:
http://msdn.microsoft.com/en-us/library/aa911455.aspx
I've just taken a few shortcuts with it.
The zip file contains the main .cpp file of the above project. It does not include the AddFontResource or RemoveFontResource statements.
Create a shell WinMo application and replace the main program .cpp file with it.
AddFontResource can only accept the path to a True Type font TTF file as an argument.
The thing you have got to get your head around are CALLBACK routines, they are used during most enumeration routines, and are widely used in Win32 for all sorts of things. A Win32 app's WndProc it itself a callback routine. In the case of EnumFonts, you pass the address of the callback routine to the enumerating function, which will call your function once for every instance it finds that matches your request. You terminate the sequence by returning 0 or it will carry on until there are no instances left. You have to decide what to do with the results. In my case I take the first Wingding font I'm offered, then quit.
Be aware that there is little, or no error handling in this code. I cobbled it together pretty quickly to prove the point.
I remember reading somewhere that if you drop the .TTF file in the Windows directory, and do a soft reset, then Windows will pick it up as a resident font, so the AddFontResource and RemoveFontResource functions are not required. EnumFonts() should know about it, and present it accordingly.
Well,thank you very much for that,but can you please provide me full project source,including all the files? With working project,I can better understand the font loading principle.
Unfortunately,I am too busy nowadays to discover something,that I don't understand well,so every time save is a big plus for me. Thank you very much again.
Attached,
But, it is a VS 2008 Smart Device project. EVC won't read it.
You will have to create a shell hello world project in EVC and copy the modified code in the panels above from TestFont.CPP.
Hello.
Actually i've got it working,but I still cannot discover,how to resize the font.
Where should I exactly put the lfWidth and lfHeight?
I am now a bit confused of that.
This is my code:
Functions and declarations of HFONT,CALLBACK,WM_CREATE,WM_DESTROY are present as you described.
void ShowNumber(HDC hdc, int Value,int xrect,int yrect,int wrect,int hrect,HBITMAP source)
{
EnumFonts(hdc,TEXT("Sam's Town"),(FONTENUMPROC) EnumFontsProc,NULL);
SelectObject(hdc,g_hfont);
TCHAR szText[MAX_LOADSTRING];
int width,height;
rtText.right=wrect;rtText.bottom=hrect;width=wrect-xrect;height=hrect-yrect;
TransparentImage(hdc,xrect,yrect,width,height,source,xrect,yrect,width,height,RGB(255,0,255));
SetBkMode(hdc,TRANSPARENT);
if(Value<10) wsprintf (szText, TEXT ("0%d"),Value);else wsprintf (szText, TEXT ("%d"),Value);
rtText.left=xrect ;rtText.top=yrect ;SetTextColor(hdc,RGB(0,0,0)); DrawText(hdc,szText,2,&rtText,DT_SINGLELINE | DT_LEFT | DT_TOP);
DeleteObject(g_hfont);
}
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
g_hfont = CreateFontIndirect(lplf);
return 0;
}
Click to expand...
Click to collapse
This doesn't work:
lplf.lfWidth=0;
g_hfont = CreateFontIndirect(lplf);
Click to expand...
Click to collapse
Actually I want to put one more parameter into ShowNumber() function,which will tell the function the size of the font.
You are nearly there...........
The code to set the font size will have to go in here.......
Code:
int CALLBACK EnumFontsProc(LOGFONT *lplf, TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData)
{
lplf->lfHeight=14;
lplf->lfWidth=8;
g_hfont = CreateFontIndirect(lplf);
return 0;
}
Or whatever your values are, I just picked 8 and 14 as examples. If these values are passed as variables to another function above, store them as global variables, and use them here.
As lplf is passed to this function as a pointer to a LOGFONT structure, you have to use the -> operator to access its members. lplf.lfHeight won't work as you mentioned, that is for predeclared or static structures.
These values have to be changed here in the EnumFontsProc() routine before the font is created, as we are passing that pointer to create the font.
Good Luck!!
P.S. While we are here, let's tidy it up a bit.
Replace:
Code:
if(Value<10) wsprintf(szText,TEXT ("0%d"),Value);else wsprintf (szText,TEXT("%d"),Value);
with
Code:
wsprintf(szText, TEXT ("02%d"),Value);
A very big thanks for that.
I am still beginner in C++,so something can look very comic for others.
My beloved programming language is Pascal.
I really didn't think,that -> is an operator,I've just mentioned,you wrote it as something else(something like "to")
You are more than welcome.
Some features in C/C++ are not immediately obvious, but the real battle is fighting your way through the Win32 programming model, trying to get it to do what you want. Sometimes the simplest of things become maddeningly complicated, but the effort to do it properly is usually worth the effort.
Glad you got it working, best wishes, stephj.
Hello a bit later.
First of all,thank your for your explanation and now I am using this method successfuly.
I want to ask you now,if there is a way to get fixed pitch of the font,that is truetype. With standart font I can achieve with this...
lf.lfPitchAndFamily = (tm.tmPitchAndFamily & 0xf0) | TMPF_FIXED_PITCH;
I am using font,that displays numbers in "digital" mode(7-segment display) and I get the number "1" very narrow in comparison with others(actually it is narrow on any kind display,but is displayed on right segments,so "01" has adequate spacing on hard display). Now I get "0l_" instead of "0_l",that's not preferable.
Thanks in advance for reactions.
I don't think there the above method will work as each character has it own width associated with it.
A simpler approach, a bit of a pain, but which should work, is to draw/print the numeric value out one character at a time using DrawText(). Set a RECT structure up to hold the coordinates of the top left and bottom right of the area for each character.
Setting uFormat to DT_RIGHT will force the character to right align in the RECT area, so the '1' should appear correctly. Move the left and right values along a fixed amount for each character. A bit of trial and error will be involved first until you get the values just right.
Good luck, stephj.

HTC Calculator giving wrong results

Hi
I love my desire. The HTC calculator is nice with the finger friendly buttons with haptic feedback, and I love the fact it's respecting the operator priorities. But what's wrong with the calculator?
100 - 99,9 = 0,09999999999999999
100 - 99,8 = 0,2
100 - 99,7 = 0,2999999999
100 -99,6 = 0,4
100 - 99,5 = 0,5
100 - 99,4 = 0,599999999
100 - 99,3 = 0,7
100 - 99,2= 0,7999999999
100 - 99,1 = 0,9
is this a known issue?
Do you know another calculator where you can review all the line you typed and correct it if needed, that has big buttons, has parenthesis, and that give accurate results? I used to use HiCalc on WinMo, but I can't seem to find a good substitute on android.
Turn the phone to landscape and more functions are available like parentheses. Not sure about your other points!
funny - i needed this calculator for my school time
100 - 99,2= 0,7999999999
i have same result
br stupsi
stupsi99 said:
100 - 99,2= 0,7999999999
Click to expand...
Click to collapse
Google floating point precision
nparley said:
Google floating point precision
Click to expand...
Click to collapse
Most likely this.
And I use RealCalc which seems to correct for it.
This is mad.
My calculated is screwed too. Lol
Sent from my HTC Desire using XDA App
Why are you putting commas in not decimal points? 99.7 not 99,7
^^^^ Other people in the world write things differently to us
ok...this is new...lol
do you guys think a solution is possible? or should we all get another calculator?lol
You need to get another calculator.
Seems that HTC's calculator is using floating point rather than fixed point or decimal floating point.
Regards,
Dave
it is also a problem on the Vanilla calculator.
I'm using OpenDesire and it also has this problem.
bedeabc said:
^^^^ Other people in the world write things differently to us
Click to expand...
Click to collapse
they might, but if the calculator is configured to work with points not commas I'm not surprised it fails
Edit
Wrong! Is the same with points as commas. My bad
When we use the calculator we press the . button, as there is no comma.
FYI when in the UK you write 1,002.50 the rest of the world writes 1 000,50.
HTC answered me to find another calculator on the maket, cause the HTC calculator is a basic one. LMAO I know it won't solve complex equations, but 100 - 99.9 should be solved by any basic calculator, even by a 7 year old pupil...so I guess it should be solved by a calculator that displays basic trigonometry buttons, shouldn't it?
It fails with points as well.
100-99.9=0.0999999999
So it's not a localisation thing, it's just a rubbish calculator.
This happens to any substraction having the following pattern:
n-((n-1)+p), where p = {0.9, 0.7, 0.4, 0.2}
And it doesn't matter whether the Calculator uses '.' or ',' for digits.
Very strange...
Benj555 said:
FYI when in the UK you write 1,002.50 the rest of the world writes 1 000,50.
Click to expand...
Click to collapse
That depends on your definition of the rest of the world.
The two most populous nations on the planet, namely China and India, use the point as the decimal separator, as does the US, Japan, and most of the ex-British empire.
For the most part, the "Decimal Comma" is in use in mainland Europe and most of South America.
Regards,
Dave
Benj555 said:
When we use the calculator we press the . button, as there is no comma.
FYI when in the UK you write 1,002.50 the rest of the world writes 1 000,50.
Click to expand...
Click to collapse
The 'rest of the world' write: 1.000,50 (they use the '.' to group thousands - e.g. 154.234.345,243)
nparley said:
Google floating point precision
Click to expand...
Click to collapse
Don't see why floating point should have anything to do with this. Floating point is relevant where there is a greater number of digits required to do the calculation than would normally be displayed. This is a simple subtraction of a number with one decimal place. This is just plain wrong!
norm2002 said:
Don't see why floating point should have anything to do with this. Floating point is relevant where there is a greater number of digits required to do the calculation than would normally be displayed. This is a simple subtraction of a number with one decimal place. This is just plain wrong!
Click to expand...
Click to collapse
nparley is correct.
Whomever wrote the HTC calc app used binary floating point data types. The subtraction is being performed "correctly" within the limitations imposed by the use of that data type. 0.1 cannot be exactly represented by that data type, which is why this issue shows up.
Regards,
Dave
No, in the UK we would use . to indicate decimal and , to indicate thousands. Which I think is standard?

Start programming: help for coding a vocabulary builder

Hi at all,
I would like to start coding for wp7. I already have the sdk and some knowledge about c#. However, I don't know how and where to start.
My plan is to program a vocabulary builder, that just asks a vocabulary from a database, then waits until the user has thought about the answer, then on click shows the answer and the user can say if it was right or wrong. Dependent on the answer the vocabulary's phase increases or decreases 1. There should be six phases.
No idea how to do that. I even don't know where to save the vocabularies and how to get them on the phone.
Any ideas for me?
Hi,
Depending on the size of the dictionary you could put the vocabs in one or more XML files, that will be deployed with your application. Maybe something like this:
Code:
<dictionary sourcelanguage="spanish" targetlanguage="english">
<vocab id="1" word="uno" translation="one"/>
<vocab id="2" word="dos" translation="two"/>
</dictionary>
Add the file to your project with build type content and read it e.g. with XDocument.Load("spanish.xml") => see here.
Build classes representing your XML-Structure and get a random vocabulary to display it to the user (use a public property e.g. "CurrentWord" in your ViewModel that is bound to a UI-Element in your View).
The "Show answer" button should be binded to a Command that triggers the hidden answer and the "Rate my answer" button to be shown.
To save the phases you could build up a index file that saves the IDs of the vocabularies with an integer of the phase count. This would then be saved each time the user processes words.
Hope this helps a bit.

Samsung Wave custom firmware

Are there any tutorials on how to make custom firmware for the Samsung Wave line of devices? Specifically, a custom firmware that does not signature check applications?
There isn't any tutorial as there isn't such a firmware at the moment. Try reading more posts than You write as it's getting silly - You ask lots of obvious questions without a definite purpose. It's not getting us anywhere. Maybe you should stop 'teaching others know their ****' and actually do something? Google for Mencken's Law.
Original Samsung JB6 is without Sig Check of Apps... this is the oldest FW leaked for S8500 (Wave)...
There are no mandatory RSA 1024 Certificats in JB6...
nearly all system files unsigned... because no BluetoothAppControl.so.htb or sig files...
"Problem".
I am not able to flash this Firmware with Multiloader nor with JTAG Hardware.
Because boot_loader.mbn is NOT encrypted...
For JTAG I'm not able to manipulate correct "Boot Image", because my brain to small...
Read here:
http://forum.xda-developers.com/showpost.php?p=13785413&postcount=64
http://forum.xda-developers.com/showthread.php?t=912728
Best Regards
adfree said:
"Problem".
I am not able to flash this Firmware with Multiloader nor with JTAG Hardware.
Because boot_loader.mbn is NOT encrypted...
For JTAG I'm not able to manipulate correct "Boot Image", because my brain to small...
Click to expand...
Click to collapse
I don't think encryption is the problem here. The algorithm (korean SEED) is already known and we can go both ways - decrypt and encrypt with any key (key for encryption is in plaintext in the description block being last 1024 bytes of the file. What we rather should worry about are the version signatures (with 512 bit RSA keys) also in the same block. The solution I see is loading a crafted file using some Bada 1.0/1.2 bootloader patched in the memory (the shadowed image) to ignore signature. We can do the patching through FOTA. As you have the JTAG we can experiment with that some time next week.
If I'm correct, an RSA key with a 512-bit modulus is easy to crack by modern computing standards.
There is a slight difference between feasibility and reasonable time to achieve that.
If you have enough resources then the modulus is: BF1834F775B9861F13E15BA3E01F91CED970B76F2E9D5767EC39C5C1DAD7A8AF9F2A60F131E1D3715E15FDE4B07AC04BF5FC148D95BFF180E9F675D6211F76F1
exponent: 010001
Thank you. And to be clear, that is the public key used by the bootloader to verify the operating system correct?
Sent from my DROID2 GLOBAL using XDA App
Yes, it's used to validate signatures on bootloader and apps (nucleus kernel and bada).
Each bootloader stage seems to have additional layer of security (some form of signature - 128 bytes at the end of each bootloader, includes some time variable/random data for "signing" as it's different for different releases of same version), but it's yet to be figured out .
As for factoring the 512-bit modulus (scroll down to the part about TI calculators):
http://www.javamex.com/tutorials/cryptography/rsa_key_length.shtml
This is why I said "If you have enough resources" as myself I'm not interested in waiting months for results, haven't got PS3, FPGA cluster or even several hundred PCs. Years back I thought about using public pay-phones network (tens of thousands of units with some RISC uC and FPGA) for distributed computation (back then with a phreaking crew we had such a possibility) like some symmetric and asymmetric cryptography keys brute-forcing and factorizing, but it's all gone now. Some sat-tv conditional access guys had some distributed factorization projects as well, but I never tracked what happened with that.
To make long story short, I know it's all possible with this modulus length, but I'm interested in doing it. If you or anybody have access to computing power (a large grid, cluster, cray or other supercomputer) then I'd be happy to see the results.
I have enough time to run my PC(s) day and night... weeks, months...
Maybe we should for "Brain training"... start with lower RSA...
I've never seen FREE Software for testing... only theory to use Graphiccards like NVIDIA...
Maybe someone is willing to offer Software for noobs like me to compute RSA Keys between RSA "30" and RSA "100"... to understand dreams and reality...
We could make some funny Thread. Who fastest generate "private Key", if public Key is given...
Again, only as lesson. So maximum RSA 100...
Example... with answer...
Code:
P = 0375BA25E7B805
Q = 03B4498980CEAB
Exp1 = 033842E45590F5
Exp2 = 02DCCB06EAF6C9
Coeff = 034F5F18D35B33
Priv Exp = 8A7ED170D08D37ACBC8920D1
Publ Exp = 010001
Modulus = 0CD0F3C2312AED609B775BF157
So the Question would be...
pub key = 0CD0F3C2312AED609B775BF157
Exponent 010001
Please give as private Exponent aka private Key...
Answer:
8A7ED170D08D37ACBC8920D1
adfree said:
I have enough time to run my PC(s) day and night... weeks, months...
Maybe we should for "Brain training"... start with lower RSA...
I've never seen FREE Software for testing... only theory to use Graphiccards like NVIDIA...
Maybe someone is willing to offer Software for noobs like me to compute RSA Keys between RSA "30" and RSA "100"... to understand dreams and reality...
We could make some funny Thread. Who fastest generate "private Key", if public Key is given...
Again, only as lesson. So maximum RSA 100...
Example... with answer...
Code:
P = 0375BA25E7B805
Q = 03B4498980CEAB
Exp1 = 033842E45590F5
Exp2 = 02DCCB06EAF6C9
Coeff = 034F5F18D35B33
Priv Exp = 8A7ED170D08D37ACBC8920D1
Publ Exp = 010001
Modulus = 0CD0F3C2312AED609B775BF157
So the Question would be...
pub key = 0CD0F3C2312AED609B775BF157
Exponent 010001
Please give as private Exponent aka private Key...
Answer:
8A7ED170D08D37ACBC8920D1
Click to expand...
Click to collapse
Great piece of software, if you run Windows, is xca. I've used it to make 8192-bit RSA keys. It is very simplistic, and I consider it a god send after trying to use OpenSSL via the command line.
Edit: I don't know if it will save the factors of the modulus, but I know that OpenSSL will. Anyway, give it a try.
Edit: Sorry, I didn't realize that you meant factoring RSA keys (I forgot about that). xca will generate them for you, though. Unfortunately, there is no (known) classical algorithm that can factor numbers in polynomial time. Shor's algorithm can do it in polynomial time, but only with a quantum computer.
Edit: The 512-bit key could be factored using a distributed effort. (See this: http://en.wikipedia.org/wiki/Texas_Instruments_signing_key_controversy) Time shares could also be rented on a supercomputer.
Code:
BF1834F775B9861F13E15BA3E01F91CED970B76F2E9D5767EC 39C5C1DAD7A8AF9F2A60F131E1D3715E15FDE4B07AC04BF5FC 148D95BFF180E9F675D6211F76F1
is approximately 2.0238493722395799×10^155. To factor a number you only need to test every number from 1 to the floor of the square root of said number. In this case, every number from 1 to about 4.49872134×10^77.
Master Melab said:
Code:
BF1834F775B9861F13E15BA3E01F91CED970B76F2E9D5767EC 39C5C1DAD7A8AF9F2A60F131E1D3715E15FDE4B07AC04BF5FC 148D95BFF180E9F675D6211F76F1
is approximately 2.0238493722395799×10^155. To factor a number you only need to test every number from 1 to the floor of the square root of said number. In this case, every number from 1 to about 4.49872134×10^77.
Click to expand...
Click to collapse
:/
Oh, come on, it is only comparable to the number of atoms in the universe...
The naive fraction algorithm does not make sense for large numbers - rather some specialized variants of Number Field Sieve, where you don't need to test every number
I was only laying out the fundamentals/basics.
Master Melab said:
To factor a number you only need to test every number from 1 to the floor of the square root of said number.
Click to expand...
Click to collapse
Master Melab said:
I was only laying out the fundamentals/basics.
Click to expand...
Click to collapse
The fundamental is you don't need to test every number.

Categories

Resources