【发布时间】:2011-09-19 22:24:46
【问题描述】:
什么是最好的方法来做到这一点。我有一个长度为高度*宽度的数组。我是否只是循环位图,根据循环索引将每个像素设置为数组?谢谢
[更新] 这是一个在位图上放置鱼眼失真的应用程序。我试图将像素数据存储在一个数组中,而不是调用 Bitmap.setPixel(),因为这会带来大量的 GC 开销
for (int j=0;j<dst.getHeight();j++) {
for (int i=0;i<dst.getWidth();i++) {
origPixel= input.getPixel(i,j);
getRadXStart = System.currentTimeMillis();
float x = getRadialX((float)j,(float)i,centerX,centerY,k);
float y = getRadialY((float)j,(float)i,centerX,centerY,k);
sampleImage(input,x,y);
color = ((s[1]&0x0ff)<<16)|((s[2]&0x0ff)<<8)|(s[3]&0x0ff);
// System.out.print(i+" "+j+" \\");
//if( Math.sqrt( Math.pow(i - centerX, 2) + ( Math.pow(j - centerY, 2) ) ) <= 150 ){
if (Math.pow(i - centerX, 2) + ( Math.pow(j - centerY, 2) ) <= 22500 ) {
// dst.setPixel(i, j, color);
arr[i]=color;
} else {
//dst.setPixel(i,j,origPixel);
arr[i]=origPixel;
}
}
}
Bitmap dst2 = Bitmap.createBitmap(arr,width,height,input.getConfig());
return dst2;
【问题讨论】:
-
示例代码向我们展示了什么?你在哪里设置像素?
标签: java android image-processing bitmap