2013-08-13 6 views
-1

LSB 알고리즘을 사용하는 스테 가노 그래피 프로젝트에서 일하고 있는데, 숨길 수있는 데이터에 의존하는 다른 비트로 모든 픽셀에서 최소 2 비트를 변경하지만 int 배열을 비트 맵으로 변환 할 때 픽셀을 얻을 수 없습니다. 나는 시도 했 ...이 코드입니다 .. 감사안드로이드에서 int 배열을 비트 맵으로 변환하는 방법?

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 is imageview whch u want to 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 the image in the device 
    String fileName = String.valueOf(Calendar.getInstance().getTimeInMillis()); 
    // generate the image path 
    String imagePath = Environment.getExternalStorageDirectory().toString() + File.separator + fileName + ".jpg"; 
    try {      
     // save the image as jpg 
     FileOutputStream out = new FileOutputStream(imagePath); 
     // compress the image to jpg and pass it to the output stream 
     newImage.compress(Bitmap.CompressFormat.JPEG, 90, out);  
     // save the 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 
+0

그래서 여전히 문제를 얻을? – Piyush

+0

예 @Piyush Gupta – Shatha

+0

그래서 @Antigona에 어떤 것을 권유하지 않습니까? – Piyush

답변

0

을 변경

newImage.copyPixelsFromBuffer(makeBuffer(oneD, oneD.length)); 
private static IntBuffer makeBuffer(int[] src, int n) { 

     IntBuffer dst = IntBuffer.allocate(n); 

     for (int i = 0; i < n; i++) { 

      dst.put(src[i]); 

     } 

     dst.rewind(); 

     return dst; 

    } 
+0

이 작동하지 않습니다. 이미지가 파란색이됩니다. – Shatha

+0

int 배열을 비트 맵으로 변환하는 방법을 보여 드렸습니다. 당신은 귀하의 논리가 올바른지 확인하기 위해 코드를 점검해야합니다 – yushulx

+0

감사합니다 @ yushulx,하지만 내 코드를 디버깅하고 논리가 올바른지 확인하십시오 – Shatha

관련 문제