私はAndroidでアプリケーションを開発しようとしていますが、私は問題を抱えています。解決する方法を理解できません。バイト配列からビットマップオブジェクトに変換する場合、null値が返されます。理想的な理由がありますか?
説明:
アプリケーションは、画像処理で構成され、以下のようにルーチンのものです。画像ファイル(PNG)は、n個の要素からなるdatabyteimage []のバイト配列に変換され、この配列の一部は、k個の要素と連続するdatabyteimage [i]からdatabyteimage [i + k]に、そして "i"はオフセットdatabyteimage []、LSB(Least Significant Bit)が置き換えられ、置き換えられる値は他のバイト配列から得られる。例:mの要素を持つdatareplace []、kの値はm * 8である。この操作はビット操作を使用して行われます。このプロセスの後、新しい文字列databyteimage []が作成されます。
問題:
[]戻りdisplaty又は新たな画像を表示するためにNULL新しいアレイdatabyteimageからビットマップオブジェクトを作成しようとしています。
今まで誰も私を助けなかったので、私がこの問題の解決策を見つけるのを手伝っていただければ幸いです。
***// 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 && (filePath.length() > 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 < textmess.length; ++i) {
int add = textmess[i];
for (int bit = 7; bit >= 0; --bit, ++offset) {
int b = (add >>> bit) & 1;
imagedata[offset] = (byte) ((imagedata[offset] & 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);
}
を私たち提示してくださいあなたのコードの適切な部分は、[SSCCE](http://sscce.org)として好まれます。そうでなければ、何がうまくいかないのか推測できます。 – DNA
少なくとも投稿:pngをバイトに変換する部分、バイトの扱い、バイトからビットマップを作成する部分。 – njzk2
@DNAこんにちは私はコードを入れて、私はどこに問題があるかを記述するコードにコメントを追加します。しかし、私はアンドロイドdosentのビットマップオブジェクトは、グレースケールをサポートすると思います。 – gabyoana