java - Android: how to create a bitmap from a string? -


i have text in string i'd save image. right have following code:

private void saveimage(view view){     string mpath = environment.getexternalstoragedirectory().tostring() + "/" + "spacitron.png";       string spacitron = "spacitron";     bitmap bitmap = bitmapfactory.decodebytearray(spacitron.getbytes(), 0, spacitron.getbytes().length*5);     outputstream fout = null;     file imagefile = new file(mpath);      try {         fout = new fileoutputstream(imagefile);         //this line throws null pointer exception         bitmap.compress(bitmap.compressformat.jpeg, 90, fout);         fout.flush();         fout.close();         } catch (filenotfoundexception e) {         } catch (ioexception e) {         }     } 

this not create bitmap , instead throws null pointer exception. how can save string bitmap?

create canvas object , draw text on canvas. save canvas bitmap

bitmap todisk = bitmap.createbitmap(w,h,bitmap.config.argb_8888); canvas.setbitmap(todisk);   canvas.drawtext(message, x , y, paint);  todisk.compress(bitmap.compressformat.jpeg, 100, new fileoutputstream(new file("/mnt/sdcard/viral.jpg"))); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -