C/Visual C - TIFF->BMP

 
Vista:

TIFF->BMP

Publicado por jose (18 intervenciones) el 15/10/2002 19:31:46
Necesito convertir una imagen TIFF a una BMP, me da igual hacerlo en C o Visual Basic
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Conversión de TIFF a BMP

Publicado por Alejandro (913 intervenciones) el 27/03/2025 16:46:28

Solución en C (usando la biblioteca libtiff)



Para convertir una imagen TIFF a BMP en C, puedes utilizar la biblioteca `libtiff`. Aquí tienes un ejemplo básico de cómo hacerlo:

1. Instala la biblioteca libtiff en tu sistema.
2. Código de ejemplo:

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
#include <stdio.h>
#include <tiffio.h>
#include <stdlib.h>
 
void convertTiffToBmp(const char* tiffFile, const char* bmpFile) {
    TIFF* tiff = TIFFOpen(tiffFile, "r");
    if (tiff) {
        uint32 width, height;
        size_t npixels;
        uint32* raster;
 
        TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width);
        TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height);
        npixels = width * height;
        raster = (uint32*) _TIFFmalloc(npixels * sizeof(uint32));
 
        if (raster != NULL) {
            if (TIFFReadRGBAImage(tiff, width, height, raster, 0)) {
                FILE* bmp = fopen(bmpFile, "wb");
                if (bmp) {
                    // Escribir encabezado BMP
                    // (Aquí deberías implementar la escritura del encabezado BMP)
                    // Escribir los datos de la imagen
                    fwrite(raster, sizeof(uint32), npixels, bmp);
                    fclose(bmp);
                }
            }
            _TIFFfree(raster);
        }
        TIFFClose(tiff);
    } else {
        printf("Error al abrir el archivo TIFF.\n");
    }
}
 
int main() {
    convertTiffToBmp("input.tiff", "output.bmp");
    return 0;
}

Este código es un punto de partida. Necesitarás implementar la escritura del encabezado BMP correctamente.

Solución en Visual Basic .NET



Si prefieres hacerlo en Visual Basic .NET, puedes usar el siguiente código:

1. Código de ejemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
Imports System.Drawing
Imports System.Drawing.Imaging
 
Module Module1
    Sub Main()
        Dim tiffFile As String = "input.tiff"
        Dim bmpFile As String = "output.bmp"
 
        Using img As Image = Image.FromFile(tiffFile)
            img.Save(bmpFile, ImageFormat.Bmp)
        End Using
    End Sub
End Module

Este código carga una imagen TIFF y la guarda como BMP utilizando las clases de `System.Drawing`.

Consideraciones finales


- Asegúrate de tener las bibliotecas necesarias instaladas y referenciadas en tu proyecto.
- Para el código en C, necesitarás manejar el encabezado BMP adecuadamente, lo que puede requerir más trabajo.
- En el caso de Visual Basic, asegúrate de que el archivo TIFF sea compatible con el formato que estás utilizando.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar