Hola d nuevo, , keria sabersi es posible cambiar el tamaño de una imagen con la libreria de gdiplus, estuve buscando pero solo encontre obtener estos valores.
Lo k necesito es digamos por ejemplo k saco un screem shot, una imagen de toda la pantalla o desde un archivo existente, esta seria x decir de 1024 x 768, y kiero k esta cambie a 640 x 480 x ejemplo.
Eh probado con _GDIPlus_BitmapCloneArea() pero no cambia la imagen en si
Alguna idea?
Gracias por responder
CaMbiar resolucion
CaMbiar resolucion
Aunk no m Buskes, Seguro m enkontras!
- Chefito
- Profesional del Autoit
- Mensajes: 2035
- Registrado: 21 Feb 2008, 18:42
- Ubicación: Albacete/Cuenca (España)
Re: CaMbiar resolucion
No la he probado. Ahí va una función de nuestros amigos de habla inglesa. Para ser exactos de smashly:
Espero que te sirva. Ya nos contarás como va y su funcionalidad.
Saludos.
Código: Seleccionar todo
; #FUNCTION# =========================================================================================
; Name...........: _ImageResize
; Description....: Resize an image and optionally convert it to the format you want.
; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH)
; Parameters ....: $sInImage - Full path to the image to resize / convert.
; In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff
; $sOutImage - Full path where to save the resized / converted image.
; Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff
; $iW - Width to resize image to.
; $iH - Height to resize image to.
; Return values .: Success - Return 1 and @error 0
; Failure - Return 0 and @error 1~5
; @error 1 = In File does not exist
; @error 2 = In File format not supported
; @error 3 = Out File path does not exist
; @error 4 = Out file format not supported
; @error 5 = Resize Width or Height not an integer
; Author ........: smashly
; ====================================================================================================
Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"
If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
$sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)
;OutFile path, to use later on.
$sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
If Not FileExists($sOP) Then Return SetError(3, 0, 0)
;OutFile name, to use later on.
$sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
;OutFile extension , to use for the encoder later on.
$Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)
If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)
;Start GDIPlus
_GDIPlus_Startup()
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
$iOriginalHeight = _GDIPlus_ImageGetHeight($hImage2)
$iOriginalWidth = _GDIPlus_ImageGetWidth($hImage2)
;create a blank DIBSection
If $iOriginalHeight > $iOriginalWidth then
$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iW,$iH)
Else
$hBitmap = _WinAPI_CreateCompatibleBitmapSection($iH,$iW)
EndIf
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
;Draw the loaded image onto the blank bitmap at the new size
If $iOriginalHeight > $iOriginalWidth then
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)
Else
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iH, $iW)
EndIf
;see if the image needs to be saved rotated
$Rotate = 0
If $iW < $iH and $iOriginalHeight < $iOriginalWidth then $Rotate = 1
If $iW > $iH and $iOriginalHeight > $iOriginalWidth then $Rotate = 1
;Get the encoder of to save the resized image in the format you want.
$CLSID = _GDIPlus_EncodersGetCLSID($Ext)
If $Rotate = 1 then
; Set up parameters for 90 degree rotation
$tData = DllStructCreate("int Data")
DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
$tParams = _GDIPlus_ParamInit (1)
_GDIPlus_ParamAdd ($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
EndIf
;Save the new resized image.
If $Rotate = 1 then
Msgbox(0,"Save Rotated",_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, DllStructGetPtr($tParams)) )
Else
Msgbox(0,"Save",_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID))
EndIf
;Clean up and shutdown GDIPlus.
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
Return SetError(0, 0, 1)
EndFunc ;==>_ImageResize
Func _WinAPI_CreateCompatibleBitmapSection($iWidth,$iHeight,$iBitCount=24)
$tBMI = DllStructCreate($tagBITMAPINFO)
DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4)
DllStructSetData($tBMI, "Width", $iWidth)
DllStructSetData($tBMI, "Height", $iHeight)
DllStructSetData($tBMI, "Planes", 1)
DllStructSetData($tBMI, "BitCount", $iBitCount)
$aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', _
'ptr', 0, _
'ptr', DllStructGetPtr($tBMI), _
'uint', 1, _
'ptr*', 0, _
'ptr', 0, _
'uint', 0)
Return $aDib[0]
EndFunc
Saludos.
Cita vista en algún lugar de la red: En este mundo hay 10 tipos de personas, los que saben binario y los que no ;).
Re: CaMbiar resolucion
Gracias, voy probar , y les cuento como va
Aunk no m Buskes, Seguro m enkontras!
Re: CaMbiar resolucion
Hola a todos,
se que es mi primer mensaje y encima refloto un hilo de hace tiempo, pero quisiera hacer una consulta que no se si se puede hacer.
¿Seria posible añadir/modificar el código que se muestra en este hilo para que guarde las imágenes en BMP de 8 bits (256 colores)?
Es que lo máximo que he logrado es que lo guarde como BMP de 16 bits, pero no menos. Imagino que vendrá dado por que 16, 24 o 32 bits son RGB y el de 8 bits es "indexado", pero no se como hacer está conversión.
Muchas gracias por adelantada,
Un saludo,
se que es mi primer mensaje y encima refloto un hilo de hace tiempo, pero quisiera hacer una consulta que no se si se puede hacer.
¿Seria posible añadir/modificar el código que se muestra en este hilo para que guarde las imágenes en BMP de 8 bits (256 colores)?
Es que lo máximo que he logrado es que lo guarde como BMP de 16 bits, pero no menos. Imagino que vendrá dado por que 16, 24 o 32 bits son RGB y el de 8 bits es "indexado", pero no se como hacer está conversión.
Muchas gracias por adelantada,
Un saludo,
- BasicOs
- Site Admin
- Mensajes: 2085
- Registrado: 21 Nov 2006, 19:24
- Ubicación: El Internet - (Canarias, España)
- Contactar:
Re: CaMbiar resolucion
Aquí tienes información de las funciones GdiPlus y de FreeImage(otro enlace dentro del mismo):
http://www.autoitscript.com/forum/index ... t&p=720389
Creditos a Zedna por este Convert()
Alternativamente puedes usar un programa aparte, como un conversor externo con run(), y hacer una llamada en modo batch o cmd para ejecutar la conversión irfanview.exe /parametros, que permite el modo comando http://www.irfanview.com/faq.htm
Salu22:)
http://www.autoitscript.com/forum/index ... t&p=720389
Creditos a Zedna por este Convert()
Código: Seleccionar todo
#include <GDIPlus.au3>
Convert("C:\xx\x.bmp", "C:\xx\x.jpg", 100, 300, 400)
Func Convert($file_in, $file_out, $width = -1, $height = -1, $quality = -1)
_GDIPlus_Startup ()
$TParam = _GDIPlus_ParamInit(1)
$Datas = DllStructCreate("int Quality")
DllStructSetData($Datas, "Quality", $quality)
_GDIPlus_ParamAdd($TParam, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($Datas))
$Param = DllStructGetPtr($TParam)
$sFileExt = StringRight($file_out,3) ; only simplified method (just for extensions with 3 chars)!
$clsid = _GDIPlus_EncodersGetCLSID($sFileExt)
$image = _GDIPlus_ImageLoadFromFile($file_in)
_GDIPlus_ImageSaveToFileEx($image, $file_out, $clsid, $Param)
_GDIPlus_ShutDown ()
EndFunc
Salu22:)
Re: CaMbiar resolucion
Gracias, la verdad que particularmente me es más fácil usar la aplicación externa irfanview y ejecutarla con run().BasicOs escribió: Alternativamente puedes usar un programa aparte, como un conversor externo con run(), y hacer una llamada en modo batch o cmd para ejecutar la conversión irfanview.exe /parametros, que permite el modo comando http://www.irfanview.com/faq.htm
Salu22:)
Un saludo,