Salve. Ho necessità di aggiungere dei dati (stringhe) su un'immagine in android. Se fosse JavaSE farei una cosa del genere:
In ambiente Android non esistono questi oggetti..codice:final BufferedImage image = ImageIO.read(new URL( "url immagine")); Graphics g = image.getGraphics(); g.setFont(g.getFont().deriveFont(30f)); g.drawString("scritta!", 100, 100); g.dispose(); ImageIO.write(image, "png", new File("test.png"));quindi come potrei fare? Grazie.
Update:
Sto provando a fare delle prove, per ora senza risultato:
Non funziona nel senso che non la scritta "prova" non c'è..codice://Catturo l'immagine della mappa CaptureMapScreen(); //Creo il file relativo alla mappa File file = new File("/mnt/sdcard/" + "MyMapScreen" + ".png"); Resources resources = this.getResources(); //densità per la scala float scale = resources.getDisplayMetrics().density; //creo il bitmap dal file Bitmap bitmap = BitmapFactory.decodeFile(file.getPath()); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); if(bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; } //rendo il bitmap mutabile bitmap = bitmap.copy(bitmapConfig, true); //creo il canvas sulla quale aggiungere il testo Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); //colore del testo paint.setColor(Color.WHITE); //dimensione del testo paint.setTextSize((int) (30 * scale)); //ombra testo paint.setShadowLayer(1f, 0f, 1f, Color.BLACK); //scrivo il testo sul canvas Rect bounds = new Rect(); paint.getTextBounds("prova", 0, "prova".length(), bounds); int x = (bitmap.getWidth() - bounds.width())/2; int y = (bitmap.getHeight() + bounds.height())/2; canvas.drawText("prova", x, y, paint); //Salvo il risultato nel telefono FileOutputStream out = null; try { out = new FileOutputStream("/mnt/sdcard/" + "MyMapScreen" + ".png"); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); //Creo il file da condividere File shareFile = new File("/mnt/sdcard/" + "MyMapScreen" + ".png"); //Creo l'Intent Intent shareIntent = new Intent(Intent.ACTION_SEND); //L'intent deve gestire immagini shareIntent.setType("image/jpeg"); //Inserisco l'immagine nell'intent shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(shareFile)); //Avvio l'Activity startActivity(Intent.createChooser(shareIntent, "Share"));

quindi come potrei fare? Grazie.
Rispondi quotando