2011-11-12 23 views

Respuesta

7

Es definitivamente posible.

Para escribir texto en una imagen, debe cargar la imagen en un objeto Bitmap. Luego dibuja en ese mapa de bits con las funciones Canvas y Paint. Cuando termine de dibujar, simplemente envíe el mapa de bits a un archivo.

Si solo utiliza un fondo negro, probablemente sea mejor para usted simplemente crear un mapa de bits en blanco en un lienzo, rellenarlo en negro, dibujar texto y luego volcar en un mapa de bits.

I used this tutorial to learn the basics of the canvas and paint.

Este es el código que se le busca para dar vuelta a la lona en un archivo de imagen:

OutputStream os = null; 
try { 
    File file = new File(dir, "image" + System.currentTimeMillis() + ".png"); 
    os = new FileOutputStream(file); 
    finalBMP.compress(CompressFormat.PNG, 100, os); 
    finalBMP.recycle(); // this is very important. make sure you always recycle your bitmap when you're done with it. 
    screenGrabFilePath = file.getPath(); 
} catch(IOException e) { 
    finalBMP.recycle(); // this is very important. make sure you always recycle your bitmap when you're done with it. 
    Log.e("combineImages", "problem combining images", e); 
} 
+0

cómo hacer lo mismo en javascript? cualquier biblioteca o cualquier cosa que pueda ayudarnos a hacer esto? – Chetan

6

Usando Graphics2d puede crear una imagen PNG, así:

public class Imagetest { 

    public static void main(String[] args) throws IOException { 
     File path = new File("image/base/path"); 
     BufferedImage img = new BufferedImage(100, 100, 
       BufferedImage.TYPE_INT_ARGB); 

     Graphics2D g2d = img.createGraphics(); 

     g2d.setColor(Color.YELLOW); 
     g2d.drawLine(0, 0, 50, 50); 

     g2d.setColor(Color.BLACK); 
     g2d.drawLine(50, 50, 0, 100); 

     g2d.setColor(Color.RED); 
     g2d.drawLine(50, 50, 100, 0); 

     g2d.setColor(Color.GREEN); 
     g2d.drawLine(50, 50, 100, 100); 

     ImageIO.write(img, "PNG", new File(path, "1.png")); 
    } 
} 
Cuestiones relacionadas