elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?  (Leído 15,953 veces)
jarpon

Desconectado Desconectado

Mensajes: 28


Ver Perfil
Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?
« en: 7 Junio 2023, 17:40 pm »

Necesito a partir de una coordenada de una imagen, recortarla con un margen para poder hacer un zoom.

Alguna idea con VBscript. Es possible?

Muchas gracias



En línea

Elektro Enjuto

Desconectado Desconectado

Mensajes: 121



Ver Perfil WWW
Re: Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?
« Respuesta #1 en: 1 Septiembre 2023, 08:54 am »

Puedes recortar una imagen en VBScript mediante Windows Image Acquisition (WIA). El enfoque que has mencionado de asignar una coordenada inicial desde la cual iniciar el recorte cuadrilateral hacia una u otra dirección, es adaptable al cálculo de un recorte convencional, midiendo lo que recortas y no recortas desde cada lado de la imagen. Prueba por ti mismo:

Código
  1. ' By Elektro
  2.  
  3. Option Explicit
  4.  
  5. ' Crops the image by the specified Left, Top, Right, and Bottom margins.
  6. ' ======================================================================
  7. ' Left       - Set the Left property to the left margin (in pixels)
  8. '              if you wish to crop along the left, otherwise 0 [the default]
  9. ' Top        - Set the Top property to the top margin (in pixels)
  10. '              if you wish to crop along the top, otherwise 0 [the default]
  11. ' Right      - Set the Right property to the right margin (in pixels)
  12. '              if you wish to crop along the right, otherwise 0 [the default]
  13. ' Bottom     - Set the Bottom property to the bottom margin (in pixels)
  14. '              if you wish to crop along the bottom, otherwise 0 [the default]
  15. ' FrameIndex - Set the FrameIndex property to the index of a frame if you
  16. '              wish to modify a frame other than the ActiveFrame,
  17. '              otherwise 0 [the default]
  18. Function CropImage(filepath, left, top, right, bottom, frameIndex)
  19.    Dim ImgFile, ImgProc
  20.  
  21.    ' https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-imagefile
  22.    Set ImgFile = WScript.CreateObject("WIA.ImageFile")
  23.  
  24.    ' https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-imageprocess
  25.    Set ImgProc = WScript.CreateObject("WIA.ImageProcess")
  26.  
  27.    On Error Resume Next
  28.    ImgFile.LoadFile(filepath)
  29.    If Err.Number <> 0 Then
  30.        Call WScript.Echo(Err.Description)
  31.        WScript.Quit(1)
  32.    End If
  33.  
  34.    ImgProc.Filters.Add(ImgProc.FilterInfos("Crop").FilterID)
  35.  
  36.    ImgProc.Filters(1).Properties("Left")       = left
  37.    ImgProc.Filters(1).Properties("Top")        = top
  38.    ImgProc.Filters(1).Properties("Right")      = right
  39.    ImgProc.Filters(1).Properties("Bottom")     = bottom
  40.    ImgProc.Filters(1).Properties("FrameIndex") = FrameIndex
  41.  
  42.    On Error Resume Next
  43.    Set CropImage = ImgProc.Apply(ImgFile)
  44.    If Err.Number <> 0 Then
  45.        Call WScript.Echo(Err.Description)
  46.        WScript.Quit(1)
  47.    End If
  48. End Function
  49.  
  50. Dim croppedImage
  51. Set croppedImage = CropImage("C:\image.jpg", 50, 50, 50, 50, null)
  52. croppedImage.SaveFile("C:\crop.jpg")
  53.  
  54. WScript.Quit(0)



Por si te interesa, aquí te dejo una lista estructurada de otras operaciones que puedes llevar a cabo en una imagen, con el objeto de tipo WIA.ImageProcess:

Citar
RotateFlip {FB912B7A-C57F-479C-9209-4895C1513F2D}
==================================================
Rotates, in 90 degree increments, and Flips, horizontally or vertically.

RotationAngle  - Set the RotationAngle property to 90, 180, or 270 if you wish
                 to rotate, otherwise 0 [the default]
FlipHorizontal - Set the FlipHorizontal property to True if you wish to flip
                 the image horizontally, otherwise False [the default]
FlipVertical   - Set the FlipVertical property to True if you wish to flip
                 the image vertically, otherwise False [the default]
FrameIndex     - Set the FrameIndex property to the index of a frame if you
                 wish to modify a frame other than the ActiveFrame,
                 otherwise 0 [the default]
==================================================
IP.Filters(1).Properties("RotationAngle") = 0 '[valid values from the following list: 0, 90, 180, 270]
IP.Filters(1).Properties("FlipHorizontal") = False
IP.Filters(1).Properties("FlipVertical") = False
IP.Filters(1).Properties("FrameIndex") = 0


Crop {C685961E-A385-4f41-A2E5-225A2518BA59}
==================================================
Crops the image by the specified Left, Top, Right, and Bottom margins.

Left       - Set the Left property to the left margin (in pixels)
             if you wish to crop along the left, otherwise 0 [the default]
Top        - Set the Top property to the top margin (in pixels)
             if you wish to crop along the top, otherwise 0 [the default]
Right      - Set the Right property to the right margin (in pixels)
             if you wish to crop along the right, otherwise 0 [the default]
Bottom     - Set the Bottom property to the bottom margin (in pixels)
             if you wish to crop along the bottom, otherwise 0 [the default]
FrameIndex - Set the FrameIndex property to the index of a frame if you
             wish to modify a frame other than the ActiveFrame,
             otherwise 0 [the default]
==================================================
IP.Filters(1).Properties("Left") = 0
IP.Filters(1).Properties("Top") = 0
IP.Filters(1).Properties("Right") = 0
IP.Filters(1).Properties("Bottom") = 0
IP.Filters(1).Properties("FrameIndex") = 0


Scale {4EBB0166-C18B-4065-9332-109015741711}
==================================================
Scales image to the specified Maximum Width and Maximum Height preserving
Aspect Ratio if necessary.

MaximumWidth        - Set the MaximumWidth property to the width (in pixels)
                      that you wish to scale the image to.
MaximumHeight       - Set the MaximumHeight property to the height (in pixels)
                      that you wish to scale the image to.
PreserveAspectRatio - Set the PreserveAspectRatio property to True
                      [the default] if you wish to maintain the current aspect
                      ration of the image, otherwise False and the image will
                      be stretched to the MaximumWidth and MaximumHeight
FrameIndex          - Set the FrameIndex property to the index of a frame if
                      you wish to modify a frame other than the ActiveFrame,
                      otherwise 0 [the default]
==================================================
IP.Filters(1).Properties("MaximumWidth") = 1
IP.Filters(1).Properties("MaximumHeight") = 1
IP.Filters(1).Properties("PreserveAspectRatio") = True
IP.Filters(1).Properties("FrameIndex") = 0


Stamp {F73D0AA9-30B7-417c-8143-23DBD0538F97}
==================================================
Stamps the specified ImageFile at the specified Left and Top coordinates.

ImageFile  - Set the ImageFile property to the ImageFile object that you wish
             to stamp
Left       - Set the Left property to the offset from the left (in pixels)
             that you wish to stamp the ImageFile at [default is 0]
Top        - Set the Top property to the offset from the top (in pixels) that
             you wish to stamp the ImageFile at [default is 0]
FrameIndex - Set the FrameIndex property to the index of a frame if you wish to
             modify a frame other than the ActiveFrame, otherwise 0
             [the default]
==================================================
IP.Filters(1).Properties("ImageFile") = Nothing
IP.Filters(1).Properties("Left") = 0
IP.Filters(1).Properties("Top") = 0
IP.Filters(1).Properties("FrameIndex") = 0


Exif {8F75768F-7D7C-44c4-93FE-E3EF28ECD259}
==================================================
Adds/Removes the specified Exif Property.

Remove     - Set the Remove property to True if you wish to remove the
             specified Exif property, otherwise False [the default] to add the
             specified exif property
ID         - Set the ID property to the PropertyID you wish to Add or Remove
Type       - Set the Type property to indicate the WiaImagePropertyType of the
             Exif property you wish to Add (ignored for Remove)
Value      - Set the Value property to the Value of the Exif property you wish
             to Add (ignored for Remove)
FrameIndex - Set the FrameIndex property to the index of a frame if you
             wish to modify a frame other than the ActiveFrame,
             otherwise 0 [the default]
==================================================
IP.Filters(1).Properties("Remove") = False
IP.Filters(1).Properties("ID") = -1 '[valid values in the range: Min = 0, Max = 65535, Step = 1]
IP.Filters(1).Properties("Type") = 1000
IP.Filters(1).Properties("Value") = Nothing
IP.Filters(1).Properties("FrameIndex") = 0


Frame {2C5EB755-63A8-40cb-B10D-7CF8F3E0CE71}
==================================================
Adds/Removes the specified Frame.

Remove     - Set the Remove property to True if you wish to remove the
             specified FrameIndex, otherwise False [the default] to Insert the
             ImageFile before the specified FrameIndex
ImageFile  - Set the ImageFile property to the ImageFile object whose
             ActiveFrame that you wish to add (ignored for Remove)
FrameIndex - For Remove, set the FrameIndex property to the index of the frame
             you wish to remove, otherwise for add, set the FrameIndex to the
             index of the frame to insert the ImageFile before, otherwise 0
             [the default] to append a frame from the ImageFile specified
==================================================
IP.Filters(1).Properties("Remove") = False
IP.Filters(1).Properties("ImageFile") = Nothing
IP.Filters(1).Properties("FrameIndex") = 0


ARGB {654A6A04-FB39-4d68-9B65-72E50E8323A0}
==================================================
Updates the image bits with those specified.

ARGBData -   Set the ARGBData property to the Vector of Longs that represent
             the ARGB data for the specified FrameIndex (the width and height
             must match)
FrameIndex - Set the FrameIndex property to the index of the frame whose ARGB
             data you wish to modify, otherwise 0 [the default] to modify the
             ActiveFrame
==================================================
IP.Filters(1).Properties("ARGBData") = Nothing
IP.Filters(1).Properties("FrameIndex") = 0


Convert {42A6E907-1D2F-4b38-AC50-31ADBE2AB3C2}
==================================================
Converts the resulting ImageFile to the specified type.

FormatID    - Set the FormatID property to the supported raster image format
              desired, currently you can choose from wiaFormatBMP,
              wiaFormatPNG, wiaFormatGIF, wiaFormatJPEG, or wiaFormatTIFF
Quality     - For a JPEG file, set the Quality property to any value from 1 to
              100 [the default] to specify quality of JPEG compression
Compression - For a TIFF file, set the Compression property to CCITT3, CCITT4,
              RLE or Uncompressed to specify the compression scheme,
              otherwise LZW [the default]
==================================================
IP.Filters(1).Properties("FormatID") = FormatID string GUID defined in the typelib
IP.Filters(1).Properties("Quality") = 100 '[valid values in the range: Min = 1, Max = 100, Step = 1]
IP.Filters(1).Properties("Compression") = "LZW" '[valid values from the following list: "CCITT3", "CCITT4", "LZW", "RLE", "Uncompressed"]


« Última modificación: 1 Septiembre 2023, 09:10 am por Elektro Enjuto » En línea

@%$& #$ %&#$, ¡hay que decirlo más!.
Bad4m_cod3

Desconectado Desconectado

Mensajes: 11


"a28ed83f69647d8f2a1046b9fa0e7c2c" H.P.Lovecraft


Ver Perfil
Re: Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?
« Respuesta #2 en: 4 Septiembre 2023, 06:39 am »

Puedes recortar una imagen en VBScript mediante Windows Image Acquisition (WIA). El enfoque que has mencionado de asignar una coordenada inicial desde la cual iniciar el recorte cuadrilateral hacia una u otra dirección, es adaptable al cálculo de un recorte convencional, midiendo lo que recortas y no recortas desde cada lado de la imagen. Prueba por ti mismo:

Código
  1. ' By Elektro
  2.  
  3. Option Explicit
  4.  
  5. ' Crops the image by the specified Left, Top, Right, and Bottom margins.
  6. ' ======================================================================
  7. ' Left       - Set the Left property to the left margin (in pixels)
  8. '              if you wish to crop along the left, otherwise 0 [the default]
  9. ' Top        - Set the Top property to the top margin (in pixels)
  10. '              if you wish to crop along the top, otherwise 0 [the default]
  11. ' Right      - Set the Right property to the right margin (in pixels)
  12. '              if you wish to crop along the right, otherwise 0 [the default]
  13. ' Bottom     - Set the Bottom property to the bottom margin (in pixels)
  14. '              if you wish to crop along the bottom, otherwise 0 [the default]
  15. ' FrameIndex - Set the FrameIndex property to the index of a frame if you
  16. '              wish to modify a frame other than the ActiveFrame,
  17. '              otherwise 0 [the default]
  18. Function CropImage(filepath, left, top, right, bottom, frameIndex)
  19.    Dim ImgFile, ImgProc
  20.  
  21.    ' https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-imagefile
  22.    Set ImgFile = WScript.CreateObject("WIA.ImageFile")
  23.  
  24.    ' https://learn.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-imageprocess
  25.    Set ImgProc = WScript.CreateObject("WIA.ImageProcess")
  26.  
  27.    On Error Resume Next
  28.    ImgFile.LoadFile(filepath)
  29.    If Err.Number <> 0 Then
  30.        Call WScript.Echo(Err.Description)
  31.        WScript.Quit(1)
  32.    End If
  33.  
  34.    ImgProc.Filters.Add(ImgProc.FilterInfos("Crop").FilterID)
  35.  
  36.    ImgProc.Filters(1).Properties("Left")       = left
  37.    ImgProc.Filters(1).Properties("Top")        = top
  38.    ImgProc.Filters(1).Properties("Right")      = right
  39.    ImgProc.Filters(1).Properties("Bottom")     = bottom
  40.    ImgProc.Filters(1).Properties("FrameIndex") = FrameIndex
  41.  
  42.    On Error Resume Next
  43.    Set CropImage = ImgProc.Apply(ImgFile)
  44.    If Err.Number <> 0 Then
  45.        Call WScript.Echo(Err.Description)
  46.        WScript.Quit(1)
  47.    End If
  48. End Function
  49.  
  50. Dim croppedImage
  51. Set croppedImage = CropImage("C:\image.jpg", 50, 50, 50, 50, null)
  52. croppedImage.SaveFile("C:\crop.jpg")
  53.  
  54. WScript.Quit(0)



Por si te interesa, aquí te dejo una lista estructurada de otras operaciones que puedes llevar a cabo en una imagen, con el objeto de tipo WIA.ImageProcess:


Muy buen codigo, tambien esta muy limpio... Que otros modulos u objectos existen para el tratamiento de imagenes y videos con VBS? Saludos
En línea

Elektro Enjuto

Desconectado Desconectado

Mensajes: 121



Ver Perfil WWW
Re: Se puede recortar una imagen bmp desde una coordenada de la imargen con VBscript?
« Respuesta #3 en: 4 Septiembre 2023, 16:26 pm »

Muy buen codigo, tambien esta muy limpio... Que otros modulos u objectos existen para el tratamiento de imagenes y videos con VBS? Saludos

Tendría que investigarlo, pero dentro de las limitaciones de VBS al parecer no hay nada que sea tan sofisticado como WIA... a menos que encuentres librerías comerciales especializadas de terceros, y poca cosa o nada va a haber tampoco para la manipulación de un stream orientado al procesamiento de video en un lenguaje como VBS.

Saludos.
En línea

@%$& #$ %&#$, ¡hay que decirlo más!.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
duda sobre recortar una imagen
Diseño Gráfico
crow666 5 3,147 Último mensaje 4 Septiembre 2007, 23:53 pm
por _loko_
Coordenada de imagen
Programación Visual Basic
hannah 0 1,218 Último mensaje 15 Noviembre 2008, 19:11 pm
por hannah
recortar imagen de 5cm de diametro con photoshop
Diseño Gráfico
winsor 1 8,422 Último mensaje 13 Septiembre 2010, 19:40 pm
por Azielito
Se puede grabar la imagen desde un conmutador KMV D-Link 2 pc's ?
Hardware
jeremy100 0 3,544 Último mensaje 23 Abril 2011, 04:44 am
por jeremy100
Recortar o seleccionar una sección de una imagen en HTML
Desarrollo Web
rolomo 3 9,355 Último mensaje 8 Febrero 2012, 02:58 am
por rolomo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines