Jump to content

Best way to annotate (large) 1bit BMP file ?


Myicq
 Share

Recommended Posts

I have a need to create and annotate a (large) BMP file, which needs to be 1bit (only b/w).

An example is here

The example is 3000x1200, created with PaintShopPro.

I would imagine this could be done with one of these tools:

  • ImageMagick (have tried, but I always get a 24 bit image and very small text)
  • GDI+ (new to this one, could not find any examples)
  • FreeImage (not sure about this one)

Do anyone have an example of this ? The font and size of demo is not important, I am more interested in the method.

Thankful for any pointers in the right direction.

 

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

Link to comment
Share on other sites

Try this:

#include <GDIPlus.au3>

_GDIPlus_Startup()

$hBitmap_1bit = _GDIPlus_BitmapCreateFromScan0(3000, 1200, $GDIP_PXF01INDEXED)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_1bit)
_GDIPlus_GraphicsClear($hCtxt, 0xFFFFFFFF)
_GDIPlus_GraphicsDrawString($hCtxt, "Large image", 100, 200, "Arial", 350)
_GDIPlus_GraphicsDispose($hCtxt)
_GDIPlus_ImageSaveToFile($hBitmap_1bit, @ScriptDir & "\Bitmap_1bit.bmp")
_GDIPlus_BitmapDispose($hBitmap_1bit)
ShellExecute(@ScriptDir & "\Bitmap_1bit.bmp")
_GDIPlus_Shutdown()


Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try this:

 

UEZ, thanks for taking the time to help out.

I tried the code, it does make an image in 1 bit, in right size and format. But the image is all black.. which seems strange because you put 0xFFFFFF for white.

I will experiment a bit with this starting point. Any other input meanwhile would be great :)

Think I need to dig into and learn GDI+. 

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

Link to comment
Share on other sites

Seems to be that _GDIPlus_ImageGetGraphicsContext cannot handle this bitmap format under WinXP.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...