Sign in to follow this  
Followers 0
Myicq

Creating BMPs with text strings

3 posts in this topic

I have seen this question asked (and ) before, but my needs are a little different so I am only 90% of the way. Hope someone can give the final puzzle piece.

Here is what I need:

* from a text file which is Unicode UTF8 (BOM), read strings one by one

* create a BMP file of 300 px high and place textline on it

- BMP must be 2 bit (b/w only)

* save BMP

* read next line

In the end there is as many different BMPs as there are lines in text file.

I know how to operate _GDI_GraphicsDrawstring, that part is simple.

But what I can't find the answer to is

1) how to calculate the space needed horizontally by a given string in 300 px height

2) how to create a white-background BMP in memory, so it can be populated and written to disc.

Point 2) is the most important, the auto-font-size-calculation can come later. For now it's trial and error.

Referring to ImageMagick, this would be

$image->ReadImage('canvas:white');

The purpose is to use images in an industrial microcontroller. Therefore the need for 2bit BMP and 300px exact in height.

Thanks for any help


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites



B&W is 1bpp , not 2 ?

1) Give by Melba23 a try.

2) Create a 1bpp graphics of the required size, draw text inside it and save it as BMP.

Look at (for instance) You don't need much of it but it should have you started. There are many graphics examples around.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I asked a somewhat related question, and ended up solving it with the help of monoscout999:

I think perhaps you can modify the _GDIPlus_BitmapCreateFromScan0() function to create the base image that you want (see it at the bottom of monoscout999's code).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • rootx
      By rootx
      I need help with unicode char ü I get some text from online json but if try to read 4 example Zürich I heave  Zürich.
      How can I convert with autoit unicode to a clear character readable? thx
    • legend
      By legend
      Hello
      I'm using the code below to send mails using our internal relay server. 
      We got a Helpdesk system named Remedy. Our users can send us a mails using outlook 2010, and we'll get a ticket.
      The problem is if I send a mail using the above script our ticket system can't display unicode characters, like ex: Æ Ø Å. It will display them as: questionmarks: "? ? ?" inside our ticket system. In the outlook inbox it looks fine showing unicode symbols, but in our ticket system the unicode characters will be replaced by questionmarks.
      The thing is, if they send a mail using outlook, it works fine, but using the script above it doesen't.
      I tried to save my script with encoding: UTF-8 with BOM, but it didn't fix it.
       
      All suggestions are very welcome
       
       
       
       
    • Jefrey
      By Jefrey
      Non-important short long story: I was facing several troubles when working with a webservice made in PHP and an AutoIt client. The AutoIt client had to send some data to the PHP webservice, then it would get back part of the data (with additional data) back to AutoIt, then send through Json to another webservice and end up in a TV system (huff). As I was using mostly Inet* functions, working with charsets became complicated, as it had to encode, decode, encode... and the mess is done. On the other end I was receiving a completely buggy string with several problems in accentuated characters (note that I live in Brazil, we speak portuguese that contains a lot of accented chars - Ááãç...). I tried and tried mixing utf_encodes and decodes everywhere, in PHP and Javascript. Wouldn't it be easier if I could just force the string to be UTF-8 and screw everything else? So I found toUTF8() PHP function.
      I've ported toUTF8() function (truly, the whole Encoding class) by Sebastián Grignoli to AutoIt. It offers useful functions to force a string to be in a specified charset in a really easy way.
      From the readme file:
      Usage
      $utf8_string = toUTF8($utf8_or_latin1_or_mixed_string) $latin1_string = toLatin1($utf8_or_latin1_or_mixed_string) Also:
      $utf8_string = fixUTF8($garbled_utf8_string) fixUTF8() converts the string to UTF-8 repeatedly until make sure it has only UTF-8 valid chars (it's really UTF-8).
      Example:
      #include 'forceutf8.au3' MsgBox(0, '', fixUTF8( 'ãé' ) ) Will output:
      ãé Note that it's just a port. If you look at both the source codes together (PHP and AutoIt), you'll see that they're exactly the same thing, but in different approaches (PHP arrays converted to Scripting.Dictionary objects, function renames, syntax porting, a few functions completely rewritten due to differences between PHP and AutoIt). Therefore, all credits goes to Sebastián Grignol.
      It seems that it works only with latin/roman alphabet (used by English).
      Downloads
      Download ZIP from Github
      Wanna help?
      Fork me on Github
    • mikezunya
      By mikezunya
      sqlite database written in ANSI code reading?The current version is based on UTF 8 encoding to read and write。
      UNICODE or ANSI transfer method
       
    • Wicked_Caty
      By Wicked_Caty
      I made a small program that should get the unicode code of an array, save it in a variable, and write it into an file. That should be done for every array of a string.
      For $i = 0 To $len Step 1 ; $len is the length of the text I enter previously $tmp0 = ChrW($text[$i]) ; $text is the text FileWrite($f, $tmp0 & @CRLF) ; $f is the file I write into $tmp0 = "" Next Building and compiling finish without raising warnings or errors, but the program fails when it's supposed to get the unicode code of that array... 
      The error message says "Line 357 (File "D:\documents\coding\Crypt\Crypt.exe"): Error: Subscript used on non-accessible variable."
      My code ends at line 141, so it's not a problem with my code as such. I'd say that ChrW() isn't able to handle the variable I give it. I don't think it's a problem with the string, but I suspect that it's because I use a variable as an index ($text[$i]).
      If my clue was right, how do I fix it? If not, what could be the problem? Thanks for the help!