私のアンドロイドアプリケーションで。私は次のようにコードからjpeg画像からバイナリコードを得ました。バイナリデータをイメージに変換する方法は?
byte[] val = stream.toByteArray();
BigInteger bi = new BigInteger(val);
String s = bi.toString(2);
この文字列sは、画像のバイナリ値を出力します。 私の質問は、このバイナリ形式をjpegイメージに変換する方法です。
私のアンドロイドアプリケーションで。私は次のようにコードからjpeg画像からバイナリコードを得ました。バイナリデータをイメージに変換する方法は?
byte[] val = stream.toByteArray();
BigInteger bi = new BigInteger(val);
String s = bi.toString(2);
この文字列sは、画像のバイナリ値を出力します。 私の質問は、このバイナリ形式をjpegイメージに変換する方法です。
私は本当にあなたが望むものではありません。
あなたはその後ImageView
-instanceにそのBitmap
をBitmapFactory
を使用して表示することができ、ストリームから直接Bitmap
-instanceを作成する場合:あなたは、文字列を変換したい場合は
Bitmap image = BitmapFactory.decodeStream(stream);
imageView.setImageBitmap(image);
基数2の表現をバイナリ配列に戻すと、BigInteger
も使用できます。
BigInteger bigInt = new BigInteger(s, 2);
byte[] binaryData = bigInt.toByteArray();
Kloberあなたは私の質問を正しく理解しました。これは素晴らしいです。あなたの返事をありがとう –
Bitmap bmp=BitmapFactory.decodeByteArray(val, 0, val.length);
ImageView img = new ImageView(this);
img.setImageBitmap(bmp);
希望これは
編集に役立ちます: は外部メモリに書き込むには内部メモリに
FileOutputStream fout;
fout = openFileOutput("temp.jpg",Context.MODE_WORLD_WRITEABLE);
b1.compress(CompressFormat.JPEG, 100, fout);
を書き込むには
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/temp.JPEG");
bm.compress(Bitmap.CompressFormat.JPEG,90, fout);
Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
savefile(bMap,"test.jpg");
private void savefile(Bitmap bt,String file)
{
try {
ContextWrapper context=this;
FileOutputStream stream =context.openFileOutput(file, 2);
BufferedOutputStream objectOut = null;
// FileOutputStream stream =(FileOutputStream) getAssets().open("temp.txt");
try {
objectOut = new BufferedOutputStream(stream);
bt.compress(Bitmap.CompressFormat.PNG, 100, objectOut);
objectOut.flush();
objectOut.close();
}
catch (Exception e) {
// TODO Auto-generated catch block
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
}
}
私はこのコードを使用しました過去:
InputStream is = (InputStream)imageContent;
d = Drawable.createFromStream(is, "src");
ファイルにバイト配列を書きます。 – epoch