加密和解密图像时图像质量下降

问题描述 投票:0回答:1

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

The Original Image

The Scrambled Image

The New Unscrambled Image

请注意,大量颜色和信息会丢失。我尝试将其另存为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();
}

这是我保存图像的位置。

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

java android android-studio jpeg android-photos
1个回答
0
投票

我认为您必须使用这种方式非常简单。

链接:-How to encrypt and decrypt images in android?

© www.soinside.com 2019 - 2024. All rights reserved.