1

基本上,我将所有像素打乱,然后重新组合它们。但是在重新组装之后,我失去了大量的图像质量和颜色。我还注意到文件大小发生了变化,考虑到相同的像素,我认为这很奇怪。

原始图像

混乱的图像

新的解读图像

注意颜色和信息的大量损失。我尝试将其保存为 PNG 而不是 JPEG,但这似乎并没有改变任何东西。这是一些代码。

    pixels = new int[width*height];
    pixelsLength = pixels.length;
    bitmap.getPixels(pixels,0,width,0,0,width,height);

这是我得到像素数组的地方。

private void encPhaseOne(){

    load.setImageResource(R.drawable.imgload1);
    int x;
    int y;
    for(int i = 0; i < RAND_ARRAY_SIZE-1; i+=2){
        x = arr1[i];
        y = arr1[i+1];
        rowSwap(x,y);
    }
    for(int i = 0; i < RAND_ARRAY_SIZE-1; i+=2){
        x = arr4[i];
        y = arr4[i+1];
        columnSwap(x,y);
    }
}

以上是一个示例加密方法。

private void decPhaseOne(){

    load.setImageResource(R.drawable.imgload3);

    int x;
    int y;

    for(int i = RAND_ARRAY_SIZE-1; i > 0; i-=2){
        x = arr4[i];
        y = arr4[i-1];
        columnSwap(x,y);
    }
    for(int i = RAND_ARRAY_SIZE-1; i > 0; i-=2) {
        x = arr1[i];
        y = arr1[i-1];
        rowSwap(x,y);
    }
}

这是它各自的解密。

private void complete(){
    bitmap = bitmap.copy(Bitmap.Config.ARGB_8888,true);
    bitmap.setPixels(pixels,0,width,0,0,width,height);
    imgUri = getImageUri(this,bitmap);

    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    File file = new File(directory, "ENCIMG" + ".JPEG");
    if (!file.exists()) {
        Log.d("path", file.toString());
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
        done();
}

这是我保存图像的地方。

我似乎找不到丢失这么多信息的地方

4

0 回答 0