Jump to content
fenhanxue

GDI+ How to improve jpg‘s quality

Recommended Posts

fenhanxue

I want to replace the specified area of picture 1.jpg with picture 2.jpg.

my code is as follow:

#AutoIt3Wrapper_UseX64 = n
#include <GDIPlus.au3>




_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_ImageLoadFromFile(@ScriptDir&'\1.jpg')
Local $hImage_replace = _GDIPlus_ImageLoadFromFile(@ScriptDir&'\2.jpg')

;set the quality 
Local $iJPGQual = 100
Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
Local $tParams = _GDIPlus_ParamInit(10)
Local $tData = DllStructCreate("int Quality")
DllStructSetData($tData, "Quality", $iJPGQual)
Local $pData = DllStructGetPtr($tData)
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
Local $pParams = DllStructGetPtr($tParams)  
                    

Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage_replace, 98, 98, 60, 60)

_GDIPlus_ImageSaveToFileEx($hBitmap, (@ScriptDir&'\out.jpg'), $sCLSID, $pParams)
                        
;Dispose
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hImage_replace)                         
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()

 

 

however, i find the out.jpg  's  quality  is not very good , can anyone help me ?

 

 

question.jpg

 

 

 

 

====================

this is  1.jpg

1.jpg

 

 

 

=======================

this is   2.jpg

2.jpg

Share this post


Link to post
Share on other sites
argumentum

vectorize the raster. Good luck, as I don't know how.

I did not understand the question at first. The title is misleading.
I guess the amount of pixels to represent 2.jpg gives undesired results.
The only way is to have greater a resolution. More pixels.

Edited by argumentum

Share this post


Link to post
Share on other sites
junkew

I think in the encoding parameters you have to tweak to get your desired result. What happens when you save it to gif, png, tiff, bmp?

check with irfanview your imageproperties if your compression quality is indeed 100 as you are trying or that it has a different quality value

not sure if this can help http://www.mediachance.com/digicam/jpgq.htm it explains a little more

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

×

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.