2012-01-06 12 views
2

私のアンドロイドアプリケーションで。私は次のようにコードからjpeg画像からバイナリコードを得ました。バイナリデータをイメージに変換する方法は?

byte[] val = stream.toByteArray(); 
      BigInteger bi = new BigInteger(val); 
    String s = bi.toString(2); 

この文字列sは、画像のバイナリ値を出力します。 私の質問は、このバイナリ形式をjpegイメージに変換する方法です。

+0

ファイルにバイト配列を書きます。 – epoch

答えて

3

私は本当にあなたが望むものではありません。

  • あなたはその後ImageView -instanceにそのBitmapBitmapFactoryを使用して表示することができ、ストリームから直接Bitmap -instanceを作成する場合:あなたは、文字列を変換したい場合は

    Bitmap image = BitmapFactory.decodeStream(stream); 
    imageView.setImageBitmap(image); 
    
  • 基数2の表現をバイナリ配列に戻すと、BigIntegerも使用できます。

    BigInteger bigInt = new BigInteger(s, 2); 
    byte[] binaryData = bigInt.toByteArray(); 
    
+0

Kloberあなたは私の質問を正しく理解しました。これは素晴らしいです。あなたの返事をありがとう –

2
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); 
+0

バイナリ値を文字列として出力します。バイナリ値をjpegイメージに変換したい。 –

+0

SDカードに.jpgとして出力しますか? – Jana

+0

はい、絶対に:) –

0
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 

        } 


    } 
0

私はこのコードを使用しました過去:

InputStream is = (InputStream)imageContent; 
d = Drawable.createFromStream(is, "src"); 
関連する問題