0

我正在使用 LSB 算法进行隐写术项目,我在每个像素处更改最低有效 2 位,而其他位取决于要隐藏的数据,但是当我将 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   
4

1 回答 1

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;

    }
于 2013-08-13T09:44:19.457 回答