【问题标题】:how to convert int array to bitmap in android? [duplicate]如何在android中将int数组转换为位图? [复制]
【发布时间】:2013-08-13 17:44:19
【问题描述】:

我正在使用 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   

【问题讨论】:

  • 所以还是有问题??
  • 那么根据@Antigona 没有任何解决方案?
  • 这个问题已经被问及并得到了回答。查看答案:stackoverflow.com/a/7850852/1726308
  • @mira ,在你问一些问题之前,你必须在这个网站或 google.com 中搜索它。
  • @Antigona ,我测试了解决方案,但问题仍然存在

标签: android


【解决方案1】:

试一试

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;

    }

【讨论】:

  • ,这个不行,图片变蓝了
  • 我刚刚给你展示了将int数组转换为位图的方法。您应该检查您的代码以确保您的逻辑是否正确
  • 感谢@yushulx,但我调试了我的代码并确定逻辑是正确的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 2013-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多