如何在android中将int数组转换为位图?

如何在android中将int数组转换为位图?,android,Android,我在使用LSB算法的隐写术项目中工作,我在每个像素处更改最低有效2位,其他位取决于要隐藏的数据,但当我将int数组转换为位图时,我无法获得我更改的像素。。这是密码…谢谢 EditText text = (EditText) findViewById(R.id.message); String msg = text.getText().toString(); int msg_size=msg.length(); if(msg_size!=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   
EditText=(EditText)findViewById(R.id.message);
字符串msg=text.getText().toString();
int msg_size=msg.length();
如果(消息大小!=0)
{
ImageView ImageView=(ImageView)findViewById(R.id.imgView);
位图bmap=Bitmap.createBitmap(imageView.getWidth(),imageView.getHeight(),Bitmap.Config.ARGB_8888);//我是要在位图中转换的图像视图
画布=新画布(bmap);
imageView.draw(画布);
int width=bmap.getWidth();
int height=bmap.getHeight();
int[]n=新int[宽度*高度];
bmap.getPixels(0,宽度,0,0,宽度,高度);
int[]byteImage=Encode.encodeMessage(长度、宽度、高度、消息);
byteImage[0]=(字节)消息大小;
位图destBitmap=Bitmap.createBitmap(宽度、高度、,
配置ARGB_8888);
destBitmap=destBitmap.copy(Bitmap.Config.ARGB_8888,true);
对于(int x=0;x<0.length;++x)
{
oneD[x]=byteImage[x];
}
位图mImage=bmap.copy(bmap.getConfig(),bmap.isMutable());
位图newImage=Bitmap.createBitmap(宽度、高度、mImage.getConfig());
设置像素(0,宽度,0,宽度,高度);
//getPixels(byteImage,0,宽度,0,0,宽度,高度);
//在设备中保存图像
String fileName=String.valueOf(Calendar.getInstance().getTimeInMillis());
//生成图像路径
字符串imagePath=Environment.getExternalStorageDirectory().toString()+File.separator+fileName+“.jpg”;
试试{
//将图像另存为jpg
FileOutputStream out=新的FileOutputStream(imagePath);
//将图像压缩到jpg并将其传递到输出流
newImage.compress(Bitmap.CompressFormat.JPEG,90,out);
//保存图像
out.flush();
out.close();
}
捕获(异常错误)
{    
Log.e(“保存图像时出错”,Error.getMessage());
} 
sendBroadcast(新的Intent(Intent.ACTION\u MEDIA\u MOUNTED,Uri.parse(“文件:/”+Environment.getExternalStorageDirectory()));
返回100;
}//如果结束
试试看

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;

    }
newImage.copyPixelsFromBuffer(makeBuffer(oneD,oneD.length));
私有静态IntBuffer makeBuffer(int[]src,int n){
IntBuffer dst=IntBuffer.allocate(n);
对于(int i=0;i
所以仍然存在问题??所以根据@Antigona没有任何解决方案?这个问题已经被问到并回答了。查看答案:@mira,在你提问之前,你必须在这个网站或google.com上搜索它。@Antigona,我测试了解决方案,但问题仍然存在,这不起作用,图像变蓝了。我刚刚向你展示了将int数组转换为位图的方法。您应该检查代码以确保逻辑是否正确谢谢@yushulx,但我调试了代码并确保逻辑正确