Jump to content

Question about _GDIPlus_BitmapCloneArea ($GDIP_PXF08INDEXED) and another question


Recommended Posts

Posted (edited)

As the title says, I was trying to convert BMP files from 32bit to 8bit and I tried to compare the results from GDI plus and Paint.Net.

Paint.Net compressed the file and almost does not change the image while on the other hand, GDI plus compressed the file but the Image is far from the original.

 

See my attach for the results.

Original File:

118.bmp

118.bmp

 

File saved in GDI Plus:

118-gdi-8ind.bmp

118-gdi-8ind.bmp

 

File saved in Paint.Net:

118-pdn-8ind.bmp

118-pdn-8ind.bmp

And if I used the $GDIP_PXF24RGB GDI plus and Paint.Net results are the same.


Will also include the code used.

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

Example()

Func Example()
    Local $hBitmap, $hClone, $hImage, $iX, $iY
    Local $sFile = @ScriptDir & "\118.bmp"


    ; Initialize GDI+ library
    _GDIPlus_Startup()

    ; Load image
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)

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

    ; 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()

    ShellExecute(@ScriptDir & "\GDIPlus_Image.bmp")
EndFunc   ;==>Example

 

My question is, Is it possible to obtain the same result as Paint.Net using GDI plus?

 

I also have another question and I will just merge it here so I wont make another thread.

If I try to save a file with transparency and used $GDIP_PXF32ARGB and save as BMP, it does not save the file with transparency as if alpha is = FF but if I saved it as PNG it does. How can I save the file in BMP but still show the transparency?

Can someone please guide me? Thank you so much!

Edited by Nyl-
Attached Images, add the question.
Link to post
Share on other sites

Try this, seems to work better :

#include <GDIPlus.au3>

_GDIPlus_Startup()

Local $sFile = FileOpenDialog("Select an image", "", "Images (*.bmp;*.png;*.jpg;*.gif;*.tif)")
If @error Or Not FileExists($sFile) Then Exit

Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)

Local $tPalette = _GDIPlus_PaletteInitialize(256, $GDIP_PaletteTypeOptimal, 256, False, $hImage)
_GDIPlus_BitmapConvertFormat($hImage, $GDIP_PXF08INDEXED, $GDIP_DitherTypeDualSpiral8x8, $GDIP_PaletteTypeFixedHalftone256, $tPalette)

_GDIPlus_ImageSaveToFile($hImage, "test8bits.bmp")

_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

BMP does not support transparency.

Link to post
Share on other sites
Posted (edited)

Thank you for the reply sir. The result is dithered and not as clear as the PdN file but it does look really good. I will try to fiddle with the code you sent me but I am afraid that that is the optimum result that I can get. I am now really curious on how did PdN manage to compress the file that way.

 

Here is the result:

test8bits.bmp

test8bits.bmp

Edited by Nyl-
Link to post
Share on other sites
Posted (edited)

Thanks for this solution. I also have the same case. JavaScript Software Development  by  https://mlsdev.com/services/custom-software-development For making dynamic web pages, developers often use JavaScript language used with HTML. This is another scripting language used for generating dynamic web pages. To develop mobile and native applications, Java is used. But for making really interactive and informative web pages, JavaScript is again the best option.

Edited by nikmiler
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...