how to convert int array to bitmap in android? -


this question has answer here:

i'm working @ steganography project using lsb algorithm ,i change least significant 2 bits @ every pixel other bits dependent on data want hidden when convert int array bitmap can't pixels changed .. code ...thanks

 edittext text = (edittext) findviewbyid(r.id.message);     string msg = text.gettext().tostring();       int msg_size=msg.length();      if(msg_size!=0)     {       imageview imageview = (imageview) findviewbyid(r.id.imgview);        bitmap bmap  = bitmap.createbitmap(imageview.getwidth(),imageview.getheight(),bitmap.config.argb_8888);//i imageview whch u want convert in bitmap     canvas canvas = new canvas(bmap);      imageview.draw(canvas);        int width = bmap.getwidth();     int height = bmap.getheight();        int[] oned = new int[width * height];     bmap.getpixels(oned, 0, width, 0, 0, width, height);         int[] byteimage = encode.encodemessage(oned, width, height, msg);             byteimage[0]=(byte)msg_size;          bitmap destbitmap = bitmap.createbitmap(width, height,             config.argb_8888);       destbitmap = destbitmap.copy(bitmap.config.argb_8888, true);           for(int x = 0; x < oned.length; ++x)     {          oned[x]=byteimage[x];     }       bitmap mimage = bmap.copy( bmap.getconfig(),  bmap.ismutable());       bitmap newimage = bitmap.createbitmap(width, height, mimage.getconfig());      newimage.setpixels(oned, 0, width, 0, 0, width, height);      // newimage.getpixels(byteimage, 0, width, 0, 0, width, height);        //saving image in device      string filename = string.valueof(calendar.getinstance().gettimeinmillis());       // generate image path      string imagepath = environment.getexternalstoragedirectory().tostring() + file.separator +  filename + ".jpg";      try {                                // save image jpg           fileoutputstream out = new fileoutputstream(imagepath);          // compress image jpg , pass output stream           newimage.compress(bitmap.compressformat.jpeg, 90, out);             // save image          out.flush();           out.close();           }     catch (exception error)     {             log.e("error saving image", error.getmessage());         }         sendbroadcast(new intent(intent.action_media_mounted,uri.parse("file://" + environment.getexternalstoragedirectory())));     return 100;     }// end if    

have try

newimage.copypixelsfrombuffer(makebuffer(oned, oned.length)); private static intbuffer makebuffer(int[] src, int n) {          intbuffer dst = intbuffer.allocate(n);          (int = 0; < n; i++) {              dst.put(src[i]);          }          dst.rewind();          return dst;      } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -