找回密码
 加入
搜索
查看: 4821|回复: 2

[图形处理] [已解决]]如何用ColorMatrix来设置imageattibutes来保存改亮度后相应位图句柄?

[复制链接]
发表于 2015-1-19 22:21:57 | 显示全部楼层 |阅读模式
本帖最后由 oceanwind 于 2015-1-26 22:49 编辑

参考了happytc贴子http://www.autoitx.com/forum.php ... hlight=%BB%D2%B6%C8
和seniors的贴子http://www.autoitx.com/forum.php ... mp;highlight=gdi%2B
想用 _ColorMatrix_set_lum()返回一个更改亮度后的位图句柄以供 YzmToArray()调用,搞不定。
请朋友们指点,谢谢先。
#include <APIConstants.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <file.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <INet.au3>
#include <ListViewConstants.au3>
#include <Math.au3>
#include <Memory.au3>
#include <PostMessage_UDF.au3>
#include <SendMessage.au3>
;#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

            _GDIPlus_Startup()
                Local $hfileBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\GDIPlus_Image.jpg")
                Local $hfileBitmap_clone = _GDIPlus_ImageClone($hfileBitmap)
                
                $hfileBitmap = _ColorMatrix_set_lum($hfileBitmap,$hfileBitmap_clone)
                
        $YzmArray = YzmToArray($hfileBitmap)
        $oldBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hfileBitmap)
        _GDIPlus_ImageDispose($hfileBitmap)
        ;_MemGlobalFree($hData)
        _GDIPlus_Shutdown()
Func _ColorMatrix_set_lum($hfileBitmap,$hfileBitmap_clone)
            Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hfileBitmap_clone)
                Local $hIA = _GDIPlus_ImageAttributesCreate()
                
                Local $tColorMatrix, $pColorMatrix, $nBrightness
 
        $tColorMatrix = _GDIPlus_ColorMatrixCreate()
        $pColorMatrix = DllStructGetPtr($tColorMatrix)
                $nBrightness = -0.3
        _GDIPlus_ColorMatrixTranslate($tColorMatrix, $nBrightness, $nBrightness, $nBrightness, 0, 1)

        _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
                _GDIPlus_GraphicsDrawImage($hGraphics, $hfileBitmap, 100, 100)
                
                Local $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hfileBitmap)
                
                _GDIPlus_ImageAttributesDispose($hIA)
                
                Return $hBMP
                
EndFunc   ;==>_Update                 
Func YzmToArray($hImage, $func_bg = 0xffffff);background
        Local $BitmapData, $iwidth, $iheight, $Scan0, $pixelData, $s_BMPData, $i_Stride
        $iwidth = _GDIPlus_ImageGetWidth($hImage)
        $iheight = _GDIPlus_ImageGetHeight($hImage)
        $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iwidth, $iheight, $GDIP_ILMREAD, $GDIP_PXF24RGB)
        $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
        $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
        $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $iheight) & "]", $Scan0)
        ;不要使用官方论坛上提供的Abs($i_Stride) * $iheight-1,否则无法正确处理gif冗余等情形
        $s_BMPData = DllStructGetData($pixelData, "lData")
        $s_BMPData = StringTrimLeft($s_BMPData, 2);去掉头部"0x"
        Local $emptyworkingset_show = DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
                ;Local $emptyworkingset_show = DllCall('Kernel32.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
                ;MsgBox(0,"",$emptyworkingset_show,2)
        ;处理图片数组
                
                
        Local $a_return[$iheight][$iwidth], $x, $y, $s
        For $y = 0 To $iheight - 1
                            
                $s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $iwidth * 6)
                For $x = 0 To $iwidth - 1
                                        
                                        $a_return[$y][$x] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
                                                
                                Next
                                
                Next
                
        Local $xScale = Int(510 / $iwidth)
        Local $yScale = Int(180 / $iheight)
        $Scale = $xScale
        If $xScale > $yScale Then $Scale = $yScale
        GUICtrlSetPos($Pic2, 20, 20, $iwidth * $Scale + $Coordinate * 2, $iheight * $Scale + $Coordinate * 2)
        GUICtrlSetPos($Pic, 20, 290 + $offset_01, $iwidth, $iheight)
                
                ;Exit
        Return $a_return
EndFunc   ;==>YzmToArray        
                
 楼主| 发表于 2015-1-21 21:12:39 | 显示全部楼层
顶一下、谢谢
 楼主| 发表于 2015-1-26 22:49:11 | 显示全部楼层
似乎这样可以了
_GDIPlus_Startup()
                Local $hfileBitmap = _GDIPlus_BitmapCreateFromFile($selected_image_file_listview_item);ok
                ;Local $hfileBitmap = _GDIPlus_ImageLoadFromFile($selected_image_file_listview_item); ok too
                
                Local $hfileBitmap_clone = _GDIPlus_ImageClone($hfileBitmap)
                
                _ColorMatrix_set_lum($hfileBitmap)
                ;$hfileBitmap = _ColorMatrix_set_lum($hfileBitmap,$hfileBitmap_clone)
                
        $YzmArray = YzmToArray($hfileBitmap)
        $oldBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hfileBitmap)
        _GDIPlus_ImageDispose($hfileBitmap)
        ;_MemGlobalFree($hData)
        _GDIPlus_Shutdown()
        DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
                ;_output_test($YzmArray)
        Return 1
EndFunc   ;==>GetYzm
Func _ColorMatrix_set_lum($hfileBitmap)
            Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hfileBitmap)
                Local $hIA = _GDIPlus_ImageAttributesCreate()
                Local $fileW = _GDIPlus_ImageGetWidth($hfileBitmap)
        Local $fileH = _GDIPlus_ImageGetHeight($hfileBitmap)
                Local $tColorMatrix, $pColorMatrix, $nBrightness
 
        $tColorMatrix = _GDIPlus_ColorMatrixCreate()
        $pColorMatrix = DllStructGetPtr($tColorMatrix)
                $nBrightness = -0.3
        _GDIPlus_ColorMatrixTranslate($tColorMatrix, $nBrightness, $nBrightness, $nBrightness, 0, 1)

        _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pColorMatrix)
                ;_GDIPlus_GraphicsDrawImage($hGraphics, $hfileBitmap, $fileW, $fileW)
                _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hfileBitmap, 0, 0, $fileW, $fileH, 0, 0, $fileW, $fileH, $hIA)
                
                ;Local $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hfileBitmap)
                
                _GDIPlus_ImageAttributesDispose($hIA)
                
                ;Return $hBMP
                
EndFunc   ;==>_Update 
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-28 03:17 , Processed in 0.094260 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表