Facing new challenges everyday

Usando filtros para redimensionar imagens

January 22nd, 2007

Esse código redimensiona uma imagem usando escalas para ampliar/reduzir a largura e/ou altura:

1
2
3
4
5
AffineTransform transform = new AffineTransform();
transform.scale(.65, .65);
AffineTransformOp operation = new AffineTransformOp(
    transform, AffineTransformOp.TYPE_BILINEAR);
operation.filter(sourceImage, destinationImage);

Post to Twitter

Juntando imagens no Java

January 19th, 2007

Esse código abaixo é de minha autoria e exemplifica a junção de imagens usando Java:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.fastsearch.images;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ConcatImage {

    /**
     * @param args
     */

    public static void main(String[] args) {
       
        Object[] statesData = loadImages();

        BufferedImage bufferedImage = new BufferedImage(280,
                    280, BufferedImage.TYPE_INT_RGB);
       
        Graphics2D g2d = bufferedImage.createGraphics();
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, 280, 280);
       
        int index = 0;
        int size = statesData.length;
        while(index < size) {
            String fileName = (String) ((Object[])
                            statesData[index])[0];
            Integer x = (Integer) ((Object[])
                            statesData[index])[1];
            Integer y = (Integer) ((Object[])
                            statesData[index])[2];
            Color color = (Color) ((Object[])
                            statesData[index])[3];
            File file = new File(args[0] + File.separator + fileName);
            try {
                BufferedImage image = ImageIO.read(file);
                int width = image.getWidth();
                int height = image.getHeight();
                for(int posX = 0; posX < width; posX++)
                {
                    for(int posY = 0; posY < height; posY++)
                    {
                        int colorCode = image.getRGB(posX, posY);
                        if(colorCode != 0 &&
                            colorCode > new Color(0, 0, 0).getRGB())
                        {
                            image.setRGB(posX, posY,
                                                            new Color(244, 244, 244).getRGB());
                        }
                    }
                }
               
                g2d.drawImage(image, x.intValue(), y.intValue(), null);
            }
            catch (IOException error) {
                System.out.println("File not found!");
            }
            index++;
        }
        try {
            ImageIO.write(bufferedImage, "png",
                             new File(args[0] + File.separator + "BRASIL.PNG"));
        }
        catch (IOException error) {
            System.out.println("Can't generate output file!");
        }
    }

    private static Object[] loadImages() {
        Object[] imagesData = new Object[27];
       
        imagesData[0] = new Object[]{"AC.png", new Integer(0), new Integer(93), Color.CYAN};
        imagesData[1] = new Object[]{"AM.png", new Integer(0), new Integer(25), Color.BLUE};
        imagesData[2] = new Object[]{"PA.png", new Integer(101), new Integer(23), Color.YELLOW};
        imagesData[3] = new Object[]{"AP.png", new Integer(129), new Integer(10), Color.BLUE};
        imagesData[4] = new Object[]{"RO.png", new Integer(56), new Integer(95), Color.YELLOW};
        imagesData[5] = new Object[]{"RR.png", new Integer(60), new Integer(5), Color.BLUE};
        imagesData[6] = new Object[]{"AL.png", new Integer(243), new Integer(103), Color.YELLOW};
        imagesData[7] = new Object[]{"BA.png", new Integer(185), new Integer(100), Color.PINK};
        imagesData[8] = new Object[]{"CE.png", new Integer(220), new Integer(60), Color.YELLOW};
        imagesData[9] = new Object[]{"MA.png", new Integer(172), new Integer(50), Color.BLUE};
        imagesData[10] = new Object[]{"PB.png", new Integer(238), new Integer(85), Color.BLUE};
        imagesData[11] = new Object[]{"PE.png", new Integer(220), new Integer(92), Color.BLUE};
        imagesData[12] = new Object[]{"PI.png", new Integer(188), new Integer(59), Color.GREEN};
        imagesData[13] = new Object[]{"RN.png", new Integer(238), new Integer(76), Color.LIGHT_GRAY};
        imagesData[14] = new Object[]{"SE.png", new Integer(240), new Integer(106), Color.GREEN};
        imagesData[15] = new Object[]{"TO.png", new Integer(157), new Integer(75), Color.GREEN};
        imagesData[16] = new Object[]{"GO.png", new Integer(141), new Integer(128), Color.BLUE};
        imagesData[17] = new Object[]{"GO.png", new Integer(141), new Integer(128), Color.BLUE};
        imagesData[18] = new Object[]{"MT.png", new Integer(85), new Integer(90), Color.BLUE};
        imagesData[19] = new Object[]{"MS.png", new Integer(111), new Integer(157), Color.GREEN};
        imagesData[20] = new Object[]{"MG.png", new Integer(155), new Integer(140), Color.BLUE};
        imagesData[21] = new Object[]{"ES.png", new Integer(213), new Integer(166), Color.BLUE};
        imagesData[22] = new Object[]{"SP.png", new Integer(142), new Integer(175), Color.BLUE};
        imagesData[23] = new Object[]{"RJ.png", new Integer(193), new Integer(185), Color.YELLOW};
        imagesData[24] = new Object[]{"PR.png", new Integer(135), new Integer(193), Color.BLUE};
        imagesData[25] = new Object[]{"SC.png", new Integer(138), new Integer(216), Color.YELLOW};
        imagesData[26] = new Object[]{"RS.png", new Integer(117), new Integer(225), Color.YELLOW};
       
        return imagesData;
    }
   
}

Post to Twitter

A luta continua

January 4th, 2007

Apesar dos incidentes violentos ocorridos aqui no Rio de Janeiro nas últimas semanas a vida continua, o carioca continua trabalhando e acreditando que as coisas vão melhorar.
Acredito que o novo governador vai se mobilizar e fazer as coisas acontecerem, pois a situação da segurança pública e saúde coletiva aqui no Rio está caótica.
Quanto a mim, estou preocupado com compras e planos futuros, mas creio que em breve todos esses problemas estarão resolvidos.
Feliz 2007 para todos!!!

Post to Twitter

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

hosted by easy2use.net