Sign in to follow this  
Followers 0
seres

image resize using bicubic sharper

7 posts in this topic

hello, i want to use bicubic sharper for an image because its best for reduction, (tested with photoshop)

i have found posts that tells how to resize and how to use a the dll for bicubic, but i dont know how to make the sharper modificacion with the bicubic,

if theres another way to make the image better using other methods with autoit, it will help too

here is the code

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

_ImageResize("C:\Users\lalt\Desktop\autoit\autoit programs\image resize\p15pqi57peifjc4aglq6dcr9f1.jpg", @ScriptDir & "\Bliss.jpg", 157, 180)


; #FUNCTION# =========================================================================================
; Name...........: _ImageResize
; Description....: Resize an image and optionally convert it to the format you want.
; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH)
; Parameters ....: $sInImage  - Full path to the image to resize / convert.
;                               In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff
;                  $sOutImage - Full path where to save the resized / converted image.
;                               Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff
;                  $iW        - Width to resize image to.
;                  $iH        - Height to resize image to.
; Return values .: Success    - Return 1 and @error 0
;                  Failure    - Return 0 and @error 1~5
;                               @error 1 = In File does not exist
;                               @error 2 = In File format not supported
;                               @error 3 = Out File path does not exist
;                               @error 4 = Out file format not supported
;                               @error 5 = Resize Width or Height not an integer
; ====================================================================================================

Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    ;declaracion de variables
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"


    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    ;OutFile path, to use later on.
    $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))


    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    ;Start GDIPlus
    _GDIPlus_Startup()

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

;im not sure if this is better going here or if its the best form to call it
DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "hwnd", $hGraphic, "int", "7")

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)


    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
        $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    ;Prefix the number to the begining of the output filename
    $sOutImage = $sOP & $i & "_" & $sOF

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
EndFunc   ;==>_ImageResize

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't know a better way as you are already using to improve the image quality by using GdipSetInterpolationMode() with value 7.

Can you explain what do you mean with "i dont know how to make the sharper modificacion with the bicubic"?

What is a sharper modificacion? Sharpen the image after scaling?

Maybe the GDIp.au3 library may help you.

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 don't know a better way as you are already using to improve the image quality by using GdipSetInterpolationMode() with value 7.

Can you explain what do you mean with "i dont know how to make the sharper modificacion with the bicubic"?

What is a sharper modificacion? Sharpen the image after scaling?

Maybe the GDIp.au3 library may help you.

Br,

UEZ

hello, im not sure about that too, in photoshop theres an option when changing the image size called Bicubic Sharper(Best for reduction), i have compared the output of photoshop and the one with the program and photoshop is better it almost shows no sparkles or small artifacs, thats why im not sure if theres a way to ad sharper o sharpen, or another way to make the image output better

Share this post


Link to post
Share on other sites

I don't think that you can compare Photoshop with GDI+ library. If you need best quality and _GdipSetInterpolationMode() is not good enough for you then you have to use Photoshop.

I did not find any sharper function in GDI+.

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

#5 ·  Posted (edited)

#Include <FreeImage.au3>

$sSrc = 'Test.tif'
$sDst = 'Test_scaled.tif'

_FreeImage_LoadDLL('FreeImage.dll')
_FreeImage_Initialise()
$pSrc = _FreeImage_LoadU(_FreeImage_GetFIFFromFilenameU($sSrc), $sSrc)
$pDst = _FreeImage_Rescale($pSrc, _FreeImage_GetWidth($pSrc) / 2, _FreeImage_GetHeight($pSrc) / 2, $FILTER_BICUBIC)
_FreeImage_SaveU(_FreeImage_GetFIFFromFilenameU($sDst), $pDst, $sDst)
_FreeImage_Unload($sSrc)
_FreeImage_Unload($sDst)
_FreeImage_DeInitialise()

Play with the following:

$FILTER_BOX

$FILTER_BICUBIC

$FILTER_BILINEAR

$FILTER_BSPLINE

$FILTER_CATMULLROM

$FILTER_LANCZOS3

Edited by Yashied

Share this post


Link to post
Share on other sites

#Include <FreeImage.au3>

$sSrc = 'Test.tif'
$sDst = 'Test_scaled.tif'

_FreeImage_LoadDLL('FreeImage.dll')
_FreeImage_Initialise()
$pSrc = _FreeImage_LoadU(_FreeImage_GetFIFFromFilenameU($sSrc), $sSrc)
$pDst = _FreeImage_Rescale($pSrc, _FreeImage_GetWidth($pSrc) / 2, _FreeImage_GetHeight($pSrc) / 2, $FILTER_BICUBIC)
_FreeImage_SaveU(_FreeImage_GetFIFFromFilenameU($sDst), $pDst, $sDst)
_FreeImage_Unload($sSrc)
_FreeImage_Unload($sDst)
_FreeImage_DeInitialise()

Play with the following:

$FILTER_BOX

$FILTER_BICUBIC

$FILTER_BILINEAR

$FILTER_BSPLINE

$FILTER_CATMULLROM

$FILTER_LANCZOS3

thanks for the help i didnt manage to make any change to the image but i have decided ill set it to bmp when trasnforming

Share this post


Link to post
Share on other sites

I don't know a better way as you are already using to improve the image quality by using GdipSetInterpolationMode() with value 7.

Can you explain what do you mean with "i dont know how to make the sharper modificacion with the bicubic"?

What is a sharper modificacion? Sharpen the image after scaling?

Maybe the GDIp.au3 library may help you.

Br,

UEZ

thanks for your time i decided to live it in bmp

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