[已解决]请教如何把一张图片像转换成16色的bmp
本帖最后由 guoguo188 于 2013-8-16 00:23 编辑请教如何把一张图片像用[[系统自带的画图工具,“文件”》》“另存为”》》保存类型选16色位图]]一样把图片转换成16色的bmp#Include <FreeImage.au3>
Local $sFile = FileOpenDialog("Select image", @DesktopCommonDir, "All images (*.jpg;*.png;*.gif;*.bmp;)", 1)
If $sFile = "" Then Exit
_FreeImage_LoadDLL(@ScriptDir & '\FreeImage.dll')
_FreeImage_Initialise()
$FIF = _FreeImage_GetFileTypeU($sFile)
If $FIF = $FIF_UNKNOWN Then
$FIF = _FreeImage_GetFIFFromFilenameU($sFile)
EndIf
$hImage = _FreeImage_LoadU($FIF, $sFile)
$hGrey = _FreeImage_ConvertTo4Bits($hImage);将一位图转换成4位位图 必须BMP 转BMP
_FreeImage_SaveU($FIF, $hGrey, @ScriptDir & '\test.bmp')
_FreeImage_Unload($hImage)
_FreeImage_Unload($hGrey)
_FreeImage_DeInitialise()传送门
http://www.autoitx.com/forum.php?mod=viewthread&tid=39291&fromuid=7653726 可以直接轉換呀 回复 2# txen548
麻烦请说直接点
像 相关函数什么的 {:face (394):}没人鸟我 水平有限, 以下為源代碼run("mspaint.exe")
WinActivate("未命名 - 小畫家")
WinWaitActive("未命名 - 小畫家")
send("{LALT}+f")
sleep(1000)
send("a")
send("{TAB}")
sleep(1000)
send("{DOWN}")
sleep(500)
send("{UP}")
sleep(500)
send("{UP}")
sleep(500)
send("{ENTER}")
ControlClick("另存新檔","儲存(&S)","Button2")
WinActivate("小畫家")
WinWaitActive("小畫家")
ControlClick("小畫家","是(&Y)","Button1") 不知道樓主想要做成什麼效果 _GDIPlus_BitmapCreateFromScan0() 回复 7# afan
版主,我在帮助文件里搜索了半天,没找到这个函数.
请问这个函数,出自哪里?在哪可以下载到? 本帖最后由 user3000 于 2013-8-14 23:50 编辑
回复 8# guoguo188
_GDIPlus_BitmapCloneArea#include <GDIPlus.au3>
_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromFile('music.jpg')
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF16RGB555)
_GDIPlus_ImageSaveToFile($hClone, 'new.bmp')
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_BitmapDispose($hClone)
_GDIPlus_Shutdown() 回复 9# user3000
亲 这个代码试过了,我想输出的是 4位深度 16色的bmp
$GDIP_PXF16RGB555 = 16 位象素 输出的是 24位深度的bmp
而尝试用这个函数 的
$GDIP_PXF01INDEXED = 1 位象素,索引
$GDIP_PXF04INDEXED = 4 位象素,索引
$GDIP_PXF08INDEXED = 8 位象素,索引
$GDIP_PXF16GRAYSCALE = 16 位象素,灰度级
$GDIP_PXF16RGB555 = 16 位象素; 每个 RGB 分量 5 位
都不能输出图像{:face (245):} 回复 10# guoguo188
我倒没测试过你列出的这些个参数. 我竟然眼花了---直到看到你的回复---我才知道是16色而不是16位...
不过接下来的事有点意思, 我本来想在百度上搜索"$GDIP_PXF01INDEXED"之类的定义,竟然在搜索结果里发现了这个帖子http://www.autoitx.com/forum.php?mod=viewthread&tid=10294&extra=&page=1
自己慢慢看,你的问题可能在最后能找到答案. 回复 11# user3000
非常感谢 成功了 本帖最后由 duanqs 于 2015-2-20 12:23 编辑
俺又继续这个话题深挖一下:
_GDIPlus_BitmapCreateFromScan0可以支持11种不同的像素格式。#include <ScreenCapture.au3>
Global Const $GDIP_PXF32CMYK = 0x0000200F
Global Const $GDIP_PXFMAX = 0x00000010
_GDIPlus_Startup()
$iW = 300
$iH = 300
$hHBitmap = _ScreenCapture_Capture("", 0, 0, $iW, $iH) ;24 bit screen capture
$hBitmap_screen = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) ;convert bitmap format
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH, 0, $GDIP_PXF04INDEXED)
$hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImage($hGfxCtxt, $hBitmap_screen, 0, 0)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "Test.png")
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hBitmap_screen)
_GDIPlus_GraphicsDispose($hGfxCtxt)
_GDIPlus_Shutdown()
Exit
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_BitmapCreateFromScan0
; Description ...: Creates a Bitmap object based on an array of bytes along with size and format information
; Syntax.........: _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight[, $iStride = 0[, $iPixelFormat = 0x0026200A[, $pScan0 = 0]]])
; Parameters ....: $iWidth - The bitmap width, in pixels
; $iHeight - The bitmap height, in pixels
; $iStride - Integer that specifies the byte offset between the beginning of one scan line and the next. This
; +is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
; +multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four
; $iPixelFormat - Specifies the format of the pixel data. Can be one of the following:
; |$GDIP_PXF01INDEXED - 1 bpp, indexed
; |$GDIP_PXF04INDEXED - 4 bpp, indexed
; |$GDIP_PXF08INDEXED - 8 bpp, indexed
; |$GDIP_PXF16GRAYSCALE - 16 bpp, grayscale
; |$GDIP_PXF16RGB555 - 16 bpp; 5 bits for each RGB
; |$GDIP_PXF16RGB565 - 16 bpp; 5 bits red, 6 bits green, and 5 bits blue
; |$GDIP_PXF16ARGB1555- 16 bpp; 1 bit for alpha and 5 bits for each RGB component
; |$GDIP_PXF24RGB - 24 bpp; 8 bits for each RGB
; |$GDIP_PXF32RGB - 32 bpp; 8 bits for each RGB. No alpha.
; |$GDIP_PXF32ARGB - 32 bpp; 8 bits for each RGB and alpha
; |$GDIP_PXF32PARGB - 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied
; $pScan0 - Pointer to an array of bytes that contains the pixel data. The caller is responsible for
; +allocating and freeing the block of memory pointed to by this parameter.
; Return values .: Success - Returns a handle to a new Bitmap object
; Failure - 0 and either:
; |@error and @extended are set if DllCall failed
; |$GDIP_STATUS contains a non zero value specifying the error code
; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources
; Related .......: _GDIPlus_ImageDispose
; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromScan0
; Example .......; Yes
; ===============================================================================================================================
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 请问在帖子里面,如何让插入的代码具有au3格式的高亮特性呢? 请问在帖子里面,如何让插入的代码具有au3格式的高亮特性呢?
页:
[1]
2