
Quita Fondo a Imagen en Corel Draw VBA
Visual Basic para Aplicaciones
Actualizado el 22 de Agosto del 2023 por Zeus Alberto (Publicado el 14 de Agosto del 2023)
1.003 visualizaciones desde el 14 de Agosto del 2023
Bueno estoy tratando de desarrollar un codigo en VBA para Corel que elimine el fondo blanco de las imagenes, pero aun no logro aterrizar un codigo funcional. De momento estoy atorado porque el modelo de clases de Corel no soporta leer bmp.pixel, para comparar el pixel con la tolerancia, dejo el codigo haber si alguien lo puede concretar.
Espero alguien tenga una idea para resolver este tema
Les dejo algunas imagenes en PNG que he estado utilizando con este codigo.
Saludos
Atentamente
Ing. Zeus Paez







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Sub RemoveWhiteBackground()
Dim doc As Document
Dim sr As ShapeRange
Dim shape As shape
Dim bmp As Bitmap
Dim x As Long, y As Long
Dim bgColor As Long ' Utilizamos Long para almacenar el valor RGB
Dim tolerance As Integer
Set doc = ActiveDocument
Set sr = doc.ActivePage.Shapes.All
' Obtener el valor RGB para el color blanco
bgColor = RGB(255, 255, 255)
' Definir la tolerancia para el rango de colores que consideras "blanco"
tolerance = 30
For Each shape In sr
If shape.Type = cdrBitmapShape Then
Set bmp = shape.Bitmap
For x = 1 To bmp.SizeWidth ' Usar SizeWidth en lugar de GetWidth
For y = 1 To bmp.SizeHeight ' Usar SizeHeight en lugar de GetHeight
If ColorDistance(bmp.Pixel(x, y), bgColor) < tolerance Then
bmp.Pixel(x, y) = RGB(0, 0, 0) ' Cambiar el píxel a negro
End If
Next y
Next x
End If
Next shape
End Sub
Function ColorDistance(color1 As Color, color2 As Long) As Double
Dim redDiff As Double
Dim greenDiff As Double
Dim blueDiff As Double
redDiff = color1.Red - GetRValue(color2)
greenDiff = color1.Green - GetGValue(color2)
blueDiff = color1.Blue - GetBValue(color2)
ColorDistance = Sqr(redDiff ^ 2 + greenDiff ^ 2 + blueDiff ^ 2)
End Function
Espero alguien tenga una idea para resolver este tema
Les dejo algunas imagenes en PNG que he estado utilizando con este codigo.
Saludos
Atentamente
Ing. Zeus Paez







Si alguno de los archivos de descarga no funciona, comentanos aquí el error.
Comentarios... (0)
No hay comentarios