找回密码
 加入
搜索
查看: 12944|回复: 18

[图形处理] [已解决]请教如何把一张图片像转换成16色的bmp

 火.. [复制链接]
发表于 2013-8-13 15:13:58 | 显示全部楼层 |阅读模式
本帖最后由 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 ... amp;fromuid=7653726
发表于 2013-8-13 15:41:21 | 显示全部楼层
可以直接轉換呀
 楼主| 发表于 2013-8-13 15:56:32 | 显示全部楼层
回复 2# txen548


   麻烦请说直接点
像 相关函数什么的
 楼主| 发表于 2013-8-13 16:36:27 | 显示全部楼层
没人鸟我
发表于 2013-8-14 09:02:03 | 显示全部楼层
水平有限, 以下為源代碼
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")

评分

参与人数 1金钱 +10 收起 理由
guoguo188 + 10 不是要窗口操作的,我想用函数在后台操作,谢 ...

查看全部评分

发表于 2013-8-14 09:02:47 | 显示全部楼层
不知道樓主想要做成什麼效果
发表于 2013-8-14 14:08:50 | 显示全部楼层
_GDIPlus_BitmapCreateFromScan0()
 楼主| 发表于 2013-8-14 21:30:46 | 显示全部楼层
回复 7# afan

版主,我在帮助文件里搜索了半天,没找到这个函数.
请问这个函数,出自哪里?在哪可以下载到?
发表于 2013-8-14 23:13:29 | 显示全部楼层
本帖最后由 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()
 楼主| 发表于 2013-8-15 01:31:38 | 显示全部楼层
回复 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 位

都不能输出图像
发表于 2013-8-15 18:16:12 | 显示全部楼层
回复 10# guoguo188
我倒没测试过你列出的这些个参数. 我竟然眼花了---直到看到你的回复---我才知道是16色而不是16位...
不过接下来的事有点意思, 我本来想在百度上搜索"$GDIP_PXF01INDEXED"之类的定义,竟然在搜索结果里发现了这个帖子http://www.autoitx.com/forum.php ... p;extra=&page=1
自己慢慢看,你的问题可能在最后能找到答案.
 楼主| 发表于 2013-8-16 00:06:15 | 显示全部楼层
回复 11# user3000

非常感谢 成功了
发表于 2015-2-20 12:16:05 | 显示全部楼层
本帖最后由 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[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
发表于 2015-2-20 12:25:55 | 显示全部楼层
请问在帖子里面,如何让插入的代码具有au3格式的高亮特性呢?
发表于 2015-2-20 12:25:59 | 显示全部楼层
请问在帖子里面,如何让插入的代码具有au3格式的高亮特性呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 04:38 , Processed in 0.088409 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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