Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

saving bitmap as 24bit bmp



  • Please log in to reply
3 replies to this topic
noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

Saving a bitmap using Tic's gdip.ahk as a bmp results in a 32bit bmp.Anyone who knows how to change it to 24bit?It is the only place i still need to use irfanview to get it done.

 

It is difficult to find info regarding the encoderparameters if anyone has a link to info that would help me a lot!

 

 

Thanks


winXP  and ahk unicode


lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013
✓  Best Answer

Hi noname,

 

I don't know about encoder parameters, and I tried to find out, but here is a way to create a 24bit bmp using:

  • Gdip_CloneBitmapArea
  • Gdip_CreateBitmap

 

In the Gdip.ahk it has the functions:

Gdip_CreateBitmap(Width, Height, Format=0x26200A)
{
    DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, "uint", 0, "uint*", pBitmap)
    Return pBitmap
}


Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
{
	DllCall("gdiplus\GdipCloneBitmapArea", "float", x, "float", y, "float", w, "float", h
	, "int", Format, "uint", pBitmap, "uint*", pBitmapDest)
	return pBitmapDest
}

Notice the 'Format': this is setting it to 32 bit by default, if you however send this value '0x00021808' instead of using the default BAM! you got a 24 bit image.

 

Grabbed this from the example # 5:

Just replace:

pBitmap := Gdip_CreateBitmap(400, 400)

with

pBitmap := Gdip_CreateBitmap(400, 400, 0x00021808)

My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

Thanks lifeweaver you made my day happy.png

 

 

The image i need to save is on the clipboard so i used this workaround using your suggestion of creating a 24bitmap.Probably it is not the most efficient but it works and in the end that is what counts!

 

I have been looking at changing the encoderparameters but i could not find any listing of the details.

#NoEnv
SetBatchLines, -1

outfile:="image" A_Now ".bmp"

If !pToken := Gdip_Startup()
{
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
}

pBitmap_clip:=Gdip_CreateBitmapFromClipboard()

Gdip_GetDimensions(pBitmap_clip,w,h)
pBitmap := Gdip_CloneBitmapArea(pBitmap_clip,0,0,w, h,0x00021808)
Gdip_SaveBitmapToFile(pBitmap, outfile)


Gdip_DisposeImage(pBitmap)
Gdip_DisposeImage(pBitmap_clip)


Gdip_Shutdown(pToken)
ExitApp

winXP  and ahk unicode


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Probably it is not the most efficient but it works


Seems to be the only way. To acheive the same in Classic GDI, you will have to create a new 24BPP Bitmap ( matching size ) and bitblt from the source.
kWo4Lk1.png