[已解决]]如何用ColorMatrix来设置imageattibutes来保存改亮度后相应位图句柄?
本帖最后由 oceanwind 于 2015-1-26 22:49 编辑参考了happytc贴子http://www.autoitx.com/forum.php?mod=viewthread&tid=28816&highlight=%BB%D2%B6%C8
和seniors的贴子http://www.autoitx.com/forum.php?mod=viewthread&tid=38835&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
顶一下、谢谢 似乎这样可以了_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
页:
[1]