我正在嘗試更改for循環中每個像素的位圖的alpha值。位圖是通過另一個位圖的createBitmap(source,x,y,w,h)創建的。我做了一些測試,但似乎無法改變阿爾法。它是setPixel命令還是事實上它不是ARGB的位圖?Android - 更改每個像素的alpha值
我想在最後創建一個簡單的淡出效果,但現在我沒有引用原始像素顏色,只是綠色與半alpha。謝謝如果你能幫助:)
_left[1] = Bitmap.createBitmap(TestActivity.photo, 0, 0, 256, 256);
for (int i = 0; i < _left[1].getWidth(); i++)
for (int t = 0; t < _left[1].getHeight(); t++) {
int a = (_left[1].getWidth()/2) - i;
int b = (_left[1].getHeight()/2) - t;
double dist = Math.sqrt((a*a) + (b*b));
if (dist > 20) _left[1].setPixel(i, t, Color.argb(128, 0, 255, 0));
}
UPDATE:
好吧,這是我想出了,如果有人想採取位圖和淡出徑向結果。但是,是的,它是不數組很慢...感謝魯本在正確的方向
public void fadeBitmap (Bitmap input, double fadeStartPercent, double fadeEndPercent, Bitmap output) {
Bitmap tempalpha = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888);
Canvas printcanvas = new Canvas(output);
int radius = input.getWidth()/2;
double fadelength = (radius * (fadeEndPercent/100));
double fadestart = (radius * (fadeStartPercent/100));
for (int i = 0; i < input.getWidth(); i++)
for (int t = 0; t < input.getHeight(); t++) {
int a = (input.getWidth()/2) - i;
int b = (input.getHeight()/2) - t;
double dist = Math.sqrt((a*a) + (b*b));
if (dist <= fadestart) {
tempalpha.setPixel(i,t,Color.argb(255, 255, 255, 255));
} else {
int fadeoff = 255 - (int) ((dist - fadestart) * (255/(fadelength - fadestart)));
if (dist > radius * (fadeEndPercent/100)) fadeoff = 0;
tempalpha.setPixel(i,t,Color.argb(fadeoff, 255, 255, 255));
}
}
Paint alphaP = new Paint();
alphaP.setAntiAlias(true);
alphaP.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// printcanvas.setBitmap();
printcanvas.drawBitmap(input, 0, 0, null);
printcanvas.drawBitmap(tempalpha, 0, 0, alphaP);
}
'_left [1] .hasAlpha()'返回什麼? –