Sign in to follow this  
Followers 0
bogQ

monochrome bitmap

21 posts in this topic

how to pullout monochrome bitmap (black and white, not the grayscale) from normal bitmap?

i tought that $GDIP_PXF01INDEXED will work, but for some reason when i test example from _GDIPlus_BitmapCloneArea it doesnt save anything when i change its parametar format to $GDIP_PXF01INDEXED.


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites



May be can help you.


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Umm, $GDIP_PXF01INDEXED works fine for me, maybe its something else in your code.

Try this example

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hBitmap, $hClone, $hImage, $iX, $iY

    ; Initialize GDI+ library
    _GDIPlus_StartUp ()

    ; Capture 32 bit bitmap
    $hBitmap = _ScreenCapture_Capture ("")
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)

    ; Create 24 bit bitmap clone
    $iX = _GDIPlus_ImageGetWidth ($hImage)
    $iY = _GDIPlus_ImageGetHeight ($hImage)
    $hClone = _GDIPlus_BitmapCloneArea ($hImage, 0, 0, $iX, $iY, $GDIP_PXF01INDEXED)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile ($hClone, @ScriptDir & "\GDIPlus_Image.bmp")

    ; Clean up resources
    _GDIPlus_ImageDispose ($hClone)
    _GDIPlus_ImageDispose ($hImage)
    _WinAPI_DeleteObject ($hBitmap)

    ; Shut down GDI+ library
    _GDIPlus_ShutDown ()

EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites
:mellow: oops that is the same example you spoke about, have you tried it anyway?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@wakillon dont work for me, i get only white from it so its tottaly diffrent comparing to output i get when saving it from paint :mellow:

Umm, $GDIP_PXF01INDEXED works fine for me, maybe its something else in your code.

Try this example

did try the code (copy paste it to b shure im not dooing anything worng) and i still dont have that pictyre on desktop

i tryed adding

_GDIPlus_ImageSaveToFile ($hClone, @ScriptDir & "\GDIPlus_Image.bmp")
If Not FileExists(@ScriptDir & "\GDIPlus_Image.bmp") Then ConsoleWrite("Its not there, but dono why? :("&@CRLF)

and ofc i got

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\xxx\Desktop\New AutoIt v3 Script.au3"

Its not there, but dono why? :)

>Exit code: 0 Time: 0.529

tested it on XP sp3 and on Virtual PC under XP sp2 fresh instaled with identical results Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It doesn't work with this value : $GDIP_PXF01INDEXED, $GDIP_PXF04INDEXED, $GDIP_PXF08INDEXED, $GDIP_PXF16GRAYSCALE

Edit : $GDIP_PXF16ARGB1555, $GDIP_PXF32PARGB too

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

anyone know the reason why it dont work under them?


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This is creating a monochrom image:

#include <GDIPlus.au3>

$file = FileOpenDialog("Select an image", "", "Images (*.jpg;*.bmp;*.png;*.gif)")
If @error Then Exit
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile($file)
$iW = _GDIPlus_ImageGetWidth($hBitmap)
$iH = _GDIPlus_ImageGetHeight($hBitmap)
$hBMP_2bpp = _GDIPlus_BitmapCloneArea($hBitmap, 0 ,0 , $iW, $iH, $GDIP_PXF01INDEXED)
_GDIPlus_ImageSaveToFile($hBMP_2bpp, @ScriptDir & "\Test.png")
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hBMP_2bpp)
_GDIPlus_ShutDown()
Exit

Don't save it as JPG because it will automatically increase the color size.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I have tried with differents pics and test.png is not created...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

$GDIP_PXF01INDEXED works perfectly for me under Win 7, maybe it has something to do with the version of GDIPlus.dll.

I'm going to boot up the good 'ol VM with XP and run some tests, I'll let you know how it turns out.

Share this post


Link to post
Share on other sites

OK that one worked, but do you know how to get identical result like in paint when saving it under "Monochrome Bitmap (*.bmp;*.dib)", so no gray scale, only 0x000000 and 0xFFFFFF ?


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

When I open the saved image it is a 1-bit bitmap thus only 2 colors - black and white!

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

when i open it under XP its gray scale


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

$GDIP_PXF01INDEXED works perfectly for me under Win 7, maybe it has something to do with the version of GDIPlus.dll.

I'm going to boot up the good 'ol VM with XP and run some tests, I'll let you know how it turns out.

Do you think it's an OS or dll version problem ? ( i'm on xp sp3)

Where is located yours ?

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'm using Win7 x64 and it is working properly.

For WinXP try this (tested in my WinXP vm):

#include <GDIPlus.au3>

$file = FileOpenDialog("Select an image", "", "Images (*.jpg;*.bmp;*.png;*.gif)")
If @error Then Exit
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile($file)
$iW = _GDIPlus_ImageGetWidth($hBitmap)
$iH = _GDIPlus_ImageGetHeight($hBitmap)
;~ $hBMP_2bpp = _GDIPlus_BitmapCloneArea($hBitmap, 0 ,0 , $iW, $iH, $GDIP_PXF01INDEXED)
$hBMP_2bpp = ASM_Bitmap_Grey_BnW($hBitmap, 1)
ConsoleWrite(_GDIPlus_ImageSaveToFile($hBMP_2bpp, @ScriptDir & "\Test.png") & @CRLF)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hBMP_2bpp)
_GDIPlus_ShutDown()
Exit

Func ASM_Bitmap_Grey_BnW($vBmp, $iBlackAndWhite = 0, $iLight = 100) ;ASM code by AndyG
    Local $iWidth = _GDIPlus_ImageGetWidth($vBmp)
    Local $iHeight = _GDIPlus_ImageGetHeight($vBmp)
    $vBitmap = _GDIPlus_BitmapCloneArea($vBmp, 0, 0, $iWidth, $iHeight)
    Local $hBitmapData = _GDIPlus_BitmapLockBits($vBitmap, 0, 0, $iWidth, $iHeight, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32RGB)
    Local $Scan = DllStructGetData($hBitmapData, "Scan0")
    Local $Stride = DllStructGetData($hBitmapData, "Stride")
    Local $tPixelData = DllStructCreate("dword[" & (Abs($Stride * $iHeight)) & "]", $Scan)
    Local $bytecode = "0x8B7C24048B5424088B5C240CB900000000C1E202575352518B040FBA00000000BB00000000B90000000088C2C1E80888C3C1E80888C18B44240883F800772FB85555000001CB01D3F7E3C1E810BB00000000B3FFC1E30888C3C1E30888C3C1E30888C389D8595A5B5F89040FEB3B89C839C3720289D839C2720289D05089F839C3770289D839C2770289D05B01D8BBDC780000F7E3C1E810595A5B5F3B4424107213C7040FFFFFFF0083C10439D1730EE95FFFFFFFC7040F00000000EBEBC3"
    Local $tCodebuffer = DllStructCreate("byte[" & StringLen($bytecode) / 2 - 1 & "]")
    Local $Ret = DllStructSetData($tCodebuffer, 1, $bytecode)
    DllCall("user32.dll", "int", "CallWindowProcW", "ptr", DllStructGetPtr($tCodebuffer), "ptr", DllStructGetPtr($tPixelData), "int", $iWidth * $iHeight, "int", $iBlackAndWhite, "int", $iLight);
    _GDIPlus_BitmapUnlockBits($vBitmap, $hBitmapData)
    $tPixelData = 0
    $tCodebuffer = 0
    Return $vBitmap
EndFunc   ;==>ASM_Bitmap_Grey_BnW

Of course it is working also on Win7.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

My bad, it whas my Test.png from paint testing, your script did not reproduce any file.

Sry one more time for this mistake.

probably its only vista+ OS, and xp cant have it, will try thatone UEZ hope itl work

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

@UEZ

Thanks, now it works ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

@UEZ

When i change this

$hBMP_2bpp = ASM_Bitmap_Grey_BnW($hBitmap, 0 )

I get pic in grey.

Is there any way for set 2 other colors ?

Edit i know, i abuse Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

The ASM code is designed for greyscale and b&w only.

I have to ask AndyG whether he has an ASM version where you can select the bit depth of the destination image.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Ok, I saw the code that I posted works fine on Win 7 but fails on XP, I tried a couple different versions of GDI+ dlls, double checked the constants in "GDIPlusConstants.au3" but $hClone just insisted on being 0 :mellow:, I guess very awesome ASM workarounds like the one UEZ posted is the way to go for now.

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