1. Tải bản cài đặt AutoIT mới nhất

    Chào Khách. Nếu bạn mới tham gia và chưa cài đặt AutoIT.
    Vui lòng vào topic trên để tải bản AutoIT mới nhất nhé
    Dismiss Notice
  2. Quy định và nội quy

    Chào Khách. Vui lòng đọc kỹ nội quy và quy định của diễn đàn
    Để tránh bị ban một cách đáng tiếc nhé!
    Dismiss Notice
  3. Hướng dẫn chèn mã AutoIT trong diễn đàn

    Chào Khách. Vui lòng xem qua bài viết này
    Để biết cách chèn mã AutoIT trong diễn đàn bạn nhé :)
    Dismiss Notice

Hỏi đáp [Solved] Thay đổi Brightness và Contrast của hình ảnh bằng GDI+

Thảo luận trong 'Thảo luận chung - Hỏi đáp' bắt đầu bởi Thiendy, 6/12/18.

Trạng thái chủ đề:
Không mở trả lời sau này.
  1. Thiendy

    Thiendy Thành viên mới
    • 3/6

    Tham gia ngày:
    22/11/18
    Bài viết:
    14
    Đã được thích:
    3
    em có file captcha.jpg lưu ở desktop, em muốn tăng brightness và contrast của ảnh lên, rồi save lại file.
    em thấy <GDIPlus.au3> có thể làm được, nhưng không hiểu hàm chạy như thế nào.
    mong mọi người hướng dẫn

    https://i.imgur.com/G1gmso1.jpg
    [​IMG]

    vd dưới là chụp hình màn hình và tăng brightness

    Mã (AutoIt):
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <ScreenCapture.au3>
    #include <WinAPIHObj.au3>

    Example()

    Func Example()
        _GDIPlus_Startup() ;initialize GDI+
        Local Const $iWidth = 600, $iHeight = 600

        Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
        GUISetState(@SW_SHOW)

        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
        Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object

        Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0.75, 0.75, 0.75) ;create the brightness color matrix (RGB)

        _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) ;adjust the image brightness to be 75% brighter

        Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
        Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
        _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

        _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ;draw the bitmap while applying the color adjustment

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ;cleanup GDI+ resources
        _GDIPlus_ImageAttributesDispose($hIA)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
    EndFunc   ;==>Example
     
     
  2. longtu

    longtu Thành viên
    • 18/23

    Tham gia ngày:
    9/8/17
    Bài viết:
    67
    Đã được thích:
    37
    ý của bạn là hỏi cách để tăng giảm độ sáng/tương phản cho ảnh captcha dựa trên cái code tăng độ sáng cho ảnh chụp màn hình bạn đưa hả ?
     
  3. Thiendy

    Thiendy Thành viên mới
    • 3/6

    Tham gia ngày:
    22/11/18
    Bài viết:
    14
    Đã được thích:
    3
    đúng rồi ạ
     
  4. Thiendy

    Thiendy Thành viên mới
    • 3/6

    Tham gia ngày:
    22/11/18
    Bài viết:
    14
    Đã được thích:
    3
    hoặc là có cách khác cũng được ạ
     
  5. yutijang

    yutijang Thành viên năng động
    • 28/34

    Tham gia ngày:
    1/7/18
    Bài viết:
    110
    Đã được thích:
    61
    Sửa một chút vào script của bạn đưa:
    Mã (AutoIt):
    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <ScreenCapture.au3>
    #include <WinAPIHObj.au3>

    Example()

    Func Example()
        _GDIPlus_Startup() ;initialize GDI+
        Local Const $iWidth = 238, $iHeight = 52

        Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
        GUISetState(@SW_SHOW)

        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
        Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object

        Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0.75, 0.75, 0.75) ;create the brightness color matrix (RGB)

        _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) ;adjust the image brightness to be 75% brighter

        ;Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
        Local $hImage =_GDIPlus_ImageLoadFromFile("G1gmso1.jpg")
        Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
        _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

        _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) ;draw the bitmap while applying the color adjustment

        _GDIPlus_Save_to_Image(@ScriptDir & "\Gnew.jpg", $hGUI)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ;cleanup GDI+ resources
        _GDIPlus_ImageAttributesDispose($hIA)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
    EndFunc   ;==>Example


    ; #FUNCTION# =============================================================================
    ; Name.............:        _GDIPlus_Save_to_Image
    ; Description ...:      INTERNAL FUNCTION - save drawnelements in GUI to file
    ; Syntax...........:        _GDIPlus_Save_to_Image($file, $hWnd)
    ; Parameters ...:       $file - filename
    ;                               $hWnd - handle to GUI
    ; Author .........:         ptrex, ProgAndy, UEZ
    ; =========================================================================================
    Func _GDIPlus_Save_to_Image($file, $hWnd)
        Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt
        If $file <> "" Or $hWnd <> "" Then
            $size = WinGetClientSize($hWnd)
            $w = $size[0]
            $h = $size[1]
            $hDC = _WinAPI_GetDC($hWnd)
            $memDC = _WinAPI_CreateCompatibleDC($hDC)
            $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
            _WinAPI_SelectObject ($memDC, $memBmp)
            _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ;  0x00CC0020 = $SRCCOPY
            $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
            $ext = "png,bmp,jpg,tif,gif"
            $fExt = StringRight($file, 3)
            If Not StringInStr($ext, $fExt)  Then
                $CLSID = "PNG"
                $file &= ".png"
            Else
                $CLSID = $fExt
            EndIf
            $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
            If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
            _GDIPlus_ImageDispose ($hImage)
            _WinAPI_ReleaseDC($hWnd, $hDC)
            _WinAPI_DeleteDC($memDC)
            _WinAPI_DeleteObject ($memBmp)
            If $err Then Return SetError(2, 0, 0)
            Return SetError(0, 0, 0)
        Else
            Return SetError(1, 0, 0)
        EndIf
    EndFunc
    Mà hình như cái này không phải tăng giảm Brightness/Contrast,
    hãy sử dụng tool này, khá tuyệt
    https://www.autoitscript.com/forum/topic/172990-visual-image-effect-gui/
     
    Thiendy thích bài này.
  6. longtu

    longtu Thành viên
    • 18/23

    Tham gia ngày:
    9/8/17
    Bài viết:
    67
    Đã được thích:
    37
    yutijang and Thiendy like this.
  7. Thiendy

    Thiendy Thành viên mới
    • 3/6

    Tham gia ngày:
    22/11/18
    Bài viết:
    14
    Đã được thích:
    3
    thank you very much
     
Trạng thái chủ đề:
Không mở trả lời sau này.

Chia sẻ trang này

Đang tải...