Jump to content
Sign in to follow this  
a440hz

GDIPlus with 4-bit graphics?

Recommended Posts

a440hz

I can't seem to get it. :D

I'm trying to create a 720 x 480 bitmap mask for a DVD menu subpicture. For my purposes, this must be done invisibly and saved as a 4 bit png.

I'm able to create an empty bitmap, fill it with white and create black button boxes. The problem is that the result can only be saved as 32 bit color. I don't know how to either convert to 4 bit before saving or how to work in 4 bit color space top begin with.

_GDIPlus_BitmapCloneArea does not appear to allow conversion between different color bit depths.

I also tried creating a blank white 4 bit image in Photoshop and opening it with GDI but the result is still a 32bit file. I don't see a way to work with RGB brushes instead of ARGB.

Here's a sample of my code. If anyone can point me in the right direction I would be extremely thankful.

-a440Hz

#include <GDIPlus.au3>
#include <WinAPI.au3>

Global $hWnd, $hDC, $hBitmap1, $hImage1, $hGraphics1, $hBrush
Global $ARGB, $RGB, $Alpha
Global $DVDWidth = 720
Global $DVDHeight = 480
Global $DVDBgColor = "0xFFFFFF"
Global $DVDBgAlpha = "FF"
Global $DVDButtonColor = "0x000000"
Global $SafeArea = 0.1
Global $DVDButtonHeight = 24
Global $DVDButtonSpacing = 2
Global $DVDTitleVerticalOffset = 48

; Start GDI+ library
_GDIPlus_Startup ()

;Create DVD Menu Background
$hWnd = _WinAPI_GetDesktopWindow ()
$hDC = _WinAPI_GetDC ($hWnd)
$hBitmap1 = _WinAPI_CreateCompatibleBitmap ($hDC, $DVDWidth, $DVDHeight)
_WinAPI_ReleaseDC ($hWnd, $hDC)

;Draw Background
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap1)
$hGraphics1 = _GDIPlus_ImageGetGraphicsContext ($hImage1)

;Fill With Solid White  
$hBrush = _GDIPlus_BrushCreateSolid (_Color($DVDBgColor,$DVDBgAlpha))
_GDIPlus_GraphicsFillRect ($hGraphics1,0, 0, $DVDWidth, $DVDHeight,$hBrush) 

;Create greatest number of button masks (normally would be the number of songs) 
$hBrush = _GDIPlus_BrushCreateSolid (_Color($DVDButtonColor,$DVDBgAlpha))
For $i = 1 to 15
    _GDIPlus_GraphicsFillRect ($hGraphics1,($DVDWidth * $SafeArea)/2, _
    ($i * ($DVDButtonHeight + $DVDButtonSpacing)) + $DVDTitleVerticalOffset, $DVDWidth-($DVDWidth * $SafeArea), $DVDButtonHeight)   
Next    

; Save DVD Menu Mask
_GDIPlus_ImageSaveToFile ($hImage1, @ScriptDir & "\track_menu_mask.png")    

; Clean up resources
_GDIPlus_ImageDispose ($hImage1)    
_GDIPlus_BrushDispose ($hBrush)
_WinAPI_DeleteObject ($hBitmap1)
_GDIPlus_GraphicsDispose ($hGraphics1)


; Shut down GDI+ library
_GDIPlus_ShutDown ()



Func _Color($RGB,$Alpha)
    $ARGB = StringLeft($RGB,2) & $Alpha & StringRight($RGB,6)
    Return $ARGB
EndFunc
Edited by a440hz

Are you experienced?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.