gpt4 book ai didi

android - 如何在 android 中扰乱图像(图像处理)?

转载 作者:行者123 更新时间:2023-11-29 01:11:32 26 4
gpt4 key购买 nike

我一直在尝试在图像上实现这一点 -

enter image description here

在点击列表中的一个项目时被称为Scrambled Image

问题是我无法实现这一点,我得到的是旧图像的非扰乱图像。

这是我的主要 Activity 代码:

public class MainActivity extends AppCompatActivity {

static final String CAMERA_PIC_DIR = "/DCIM/Camera/";
ImageView iv;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.my_image);
String ImageDir = Environment.getExternalStorageDirectory()
.getAbsolutePath() + CAMERA_PIC_DIR;
Intent i = new Intent(this, ListFiles.class);
i.putExtra("directory", ImageDir );
startActivityForResult(i,0);
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 0 && resultCode==RESULT_OK) {
String tmp = data.getExtras().getString("clickedFile");
Bitmap ImageToChange= BitmapFactory.decodeFile(tmp);
process_image(ImageToChange);
}
}
void process_image(Bitmap image) {
Bitmap bm = Bitmap.createScaledBitmap(image, 480, 320, false);
int width = bm.getWidth();
int height = bm.getHeight();
int x= width>>1;
int y= height>>1;
int[] pixels1 = new int[(width*height)];
int[] pixels2 = new int[(width*height)];
int[] pixels3 = new int[(width*height)];
int[] pixels4 = new int[(width*height)];
bm.getPixels(pixels1, 0, width, 0, 0, width>>1, height>>1);
bm.getPixels(pixels2, 0, width, x, 0, width>>1, height>>1);
bm.getPixels(pixels3, 0, width, 0, y, width>>1, height>>1);
bm.getPixels(pixels4, 0, width, x, y, width>>1, height>>1);
if(bm.isRecycled()) {
bm.setPixels(pixels2, 0, width, 0, 0, width>>1, height>>1);
bm.setPixels(pixels4, 0, width, x, 0, width>>1, height>>1);
bm.setPixels(pixels1, 0, width, 0, y, width>>1, height>>1);
bm.setPixels(pixels3, 0, width, x, y, width>>1, height>>1);
}
iv.setImageBitmap(bm);
}
}

任何积极的回答将不胜感激。

提前感谢您的帮助!

最佳答案

您可以将 if(isRecycled()) 替换为 if(isMutable())

这应该可以解决问题!

关于android - 如何在 android 中扰乱图像(图像处理)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42655392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com