Note that there are some explanatory texts on larger screens.

plurals
  1. POIf convert from byte array to bitmap object return null value. Have any ideea why?
    text
    copied!<p>I'm trying to develop an application in Android and I'm having a problem I can't figure out how to solve. </p> <p>Description:</p> <p>The application consists of image processing and one of the routines is as follows. An image file (PNG) is converted into a array of bytes databyteimage[] with n elements, a part of this array ex: from databyteimage[i] to databyteimage[i+k] consecutive with k elements and " i " is offset databyteimage[], the LSB (Least Significant Bit) is replaced, the value what is replaced coms from other array of bytes ex:datareplace[] with m elements the value of k is m*8. This operation is done using operations on bits . After this process, a new string databyteimage[] is created. </p> <p>The problem:</p> <p>When trying to create the BITMAP object from the new array databyteimage[] returns NULL to displaty or show the new image.</p> <p>I would appreciate if you could help me find a solution to this problem, since until now no one could help me. </p> <pre><code>***// GetByte method from Image*** private byte[] getByteImageData(String filePath) { /* Bitmap bitmap = BitmapFactory.decodeFile(filePath); Bitmap mutable = bitmap.copy(Bitmap.Config.RGB_565, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mutable.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); */ byte[] _imagebytedata = new byte[1024]; InputStream _input = null; try { if (filePath != null &amp;&amp; (filePath.length() &gt; 0)) { // Create a file for image File _fileimage = new File(filePath); if (_fileimage.exists()) { // Get the byte from file image _input = new BufferedInputStream(new FileInputStream( _fileimage)); _imagebytedata = new byte[(int) _fileimage.length()]; _input.read(_imagebytedata, 0, (int) _fileimage.length()); _input.close(); } } } catch (Exception e) { } **// Bitwise operations to change LSB of byte array image** private byte[] Text(byte[] imagedata, byte[] textmess, int offset) { for (int i = 0; i &lt; textmess.length; ++i) { int add = textmess[i]; for (int bit = 7; bit &gt;= 0; --bit, ++offset) { int b = (add &gt;&gt;&gt; bit) &amp; 1; imagedata[offset] = (byte) ((imagedata[offset] &amp; 0xFE) |b); } } return imagedata; } ***//Save image from new byte array*** private boolean saveImage(String pathFile,byte[] encodedimage) { OutputStream _output = null; File _newFileImage = new File(pathFile); byte[] _encodedimage = encodedimage; //Bitmap _imagebitmap = BitmapFactory.decodeByteArray(encodedimage, 0, encodedimage.length); if (_newFileImage.exists()) { try { _output = new BufferedOutputStream(new FileOutputStream( _newFileImage)); _output.write(_encodedimage, 0, _encodedimage.length); _output.flush(); _output.close(); return true; } catch (Exception e) { } ; }// _newFileImage.exists() return false; } public boolean encodeTextInFile(String filepath, String text) { byte[] _newimagebytedata; byte[] _imagebytedata = getByteImageData(filepath); byte[] _textbytedata = text.getBytes(); byte[] _lengthbytedata = byteConversion(text.length()); _newimagebytedata = Text(_imagebytedata, _lengthbytedata, 33); _newimagebytedata = Text(_imagebytedata, _textbytedata, 65); **// The value of variable _bitmapdoi is null here is the problem** Bitmap _bitmapdoi = BitmapFactory.decodeByteArray(_newimagebytedata, 0,_newimagebytedata.length); return saveImage(filepath, _newimagebytedata); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload