Jump to content

Adding Pixels to image


Recommended Posts

anyone with ideas for this...just want to just an image and on one og the sides increase the width or height by a random pixel width and adjust the image without messing up the org image quality.

I have a script right now to change the dimensions by a number or percentage by the image quality changes with it.

Link to comment
Share on other sites

ok i got this work after some research but its not saving correctly...heres what i got:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
Local $hWnd1, $hWnd2, $hGraphic, $file, $hImage, $hBackbuffer, $hBitmap,$sRandom,$sRandom2 
Local $hFormat, $tLayout, $aInfo, $saveFile
Local $iX, $iY

$file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.png;*.bmp;*.gif)")

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($file)
$sRandom = StringFormat("%08u", Random(0,250,1))
$sRandom2 = StringFormat("%08u", Random(0,250,1))
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)

$iX  = $iX+$sRandom
$iY = $iY+$sRandom2
$hWnd1 = GUICreate("_GDIPlus_GraphicsDrawImage", $iX, $iY)
GUISetBkColor(0xffffff)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd1)


$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic)

$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImage($hBackbuffer, $hImage, 0, 0)




_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iX , $iY )

GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
Until Not Sleep(10000000)

Func _Exit()
    $saveFile = _GDIPlus_ImageSaveToFile ($hBitmap, "c:\test2.gif")
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc

the GUI will have a white background and the GUI has change size....now when is save the the new image size...the size is larger but the background is black....i need it to stay white.

thanks

Link to comment
Share on other sites

...just want to just an image and on one og the sides increase the width or height by a random pixel width and adjust the image without messing up the org image quality.......

I took the above to mean you wanted to adjust the size of an image by increasing one side, either the width or the height, by a random pixel width.

This script draws a random size edge between 0 and 250 pixels wide randomly at either the top, bottom, left or right edge of an image.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)
Global $hGUI1, $hBitmap1, $hGraphic1
Local $fname = FileOpenDialog("First image", "", "All images (*.jpg;*.png;*.gif;*.bmp;)")
If @error Then Exit

Local $sNewName1 = @DesktopCommonDir & "\Image1.png"

_RandWidthToRandEdge($fname, $sNewName1, 0, 250)

Func _RandWidthToRandEdge($fname, $sNewName, $iMin, $iMax)
    Local $hImage, $iX, $iY, $iXImage, $iYImage, $hClone, $hBackbuffer1, $Rand, $iXPos, $iYPos
    Local $aMPos, $aRet
    _GDIPlus_Startup()

    $hImage = _GDIPlus_ImageLoadFromFile($fname)
    $iXImage = _GDIPlus_ImageGetWidth($hImage)
    $iYImage = _GDIPlus_ImageGetHeight($hImage)

    ; Random size edge between 5 and 30 pixels at either top, bottom, left or right edge.
    $Rand = Random($iMin, $iMax, 1) ; Width of added edge,
    If Random(0, 1, 1) Then
        $iX = $iXImage + $Rand ; Random width
        $iY = $iYImage
        If Random(0, 1, 1) Then ; Random left or right
            $iXPos = $Rand
        Else
            $iXPos = 0
        EndIf
        $iYPos = 0
    Else
        $iX = $iXImage
        $iY = $iYImage + $Rand ; Random height
        If Random(0, 1, 1) Then
            $iYPos = $Rand ; Random top or bottom
        Else
            $iYPos = 0
        EndIf
        $iXPos = 0
    EndIf

    $hGUI1 = GUICreate("Random Add Edge", $iX, $iY)
    GUISetState()

    ;Double buffer for $hGUI1 for Re-paint
    $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($hGUI1) ; Graphics of GUI
    $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic1); Bitmap (memory only)
    $hBackbuffer1 = _GDIPlus_ImageGetGraphicsContext($hBitmap1) ; Graphics of bitmap

    GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)

    ; Gives colour to added edge.
    ;_GDIPlus_GraphicsClear($hBackbuffer1, 0xFF00FF00);green
    _GDIPlus_GraphicsClear($hBackbuffer1, 0xFFFFFFFF);white

    ; Draw image on the graphics of the larger coloured bitmap, $hBitmap1, (has extra edge).
    _GDIPlus_GraphicsDrawImage($hBackbuffer1, $hImage, $iXPos, $iYPos)

    ; Draw buffered/memory bitmap to the graphics of the GUI.
    _GDIPlus_GraphicsDrawImage($hGraphic1, $hBitmap1, 0, 0)

    ; Save bitmap to new file
    _GDIPlus_ImageSaveToFile($hBitmap1, $sNewName)
    ShellExecute($sNewName) ; View saved image

    ; Loop until user exits
    Do
        $aMPos = MouseGetPos()
        ; See _WinAPI_WindowFromPoint()
        $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $aMPos[0], "uint", $aMPos[1])
        If $aRet[0] = $hGUI1 Then
            ToolTip("Size (WxH) = " & $iXImage & "x" & $iYImage & " To " & $iX & "x" & $iY)
        Else
            ToolTip("")
        EndIf
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up file saved on disk
    FileDelete($sNewName)

    ; Release resources
    _GDIPlus_ImageDispose($hImage)
    _WinAPI_DeleteObject($hBitmap1)
    _GDIPlus_GraphicsDispose($hGraphic1)
    _GDIPlus_GraphicsDispose($hBackbuffer1)
    _GDIPlus_Shutdown()

EndFunc ;==>_RandWidthToRandEdge


Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    If $hWnd = $hGUI1 Then _GDIPlus_GraphicsDrawImage($hGraphic1, $hBitmap1, 0, 0)
    ;_WinAPI_RedrawWindow($hWnd, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN
    Return $GUI_RUNDEFMSG
EndFunc ;==>MY_PAINT
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...