我想顯示一個像素逐像素(明確意味着有一些延遲)。 我使用兩個「for」循環來做到這一點,但它只打印一行像素......如果任何人有任何想法如何做? ?請幫助..... 我的代碼是這樣的........如何逐個像素顯示位圖?
Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "Printing...", Toast.LENGTH_SHORT).show();
iImageArray = new int[bMap.getWidth()* bMap.getHeight()]; //initializing the array for the image size
bMap.getPixels(iImageArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight()); //copy pixel data from the Bitmap into the 'intArray' array
//Canvas canvas = new Canvas (bMap);
//replace the red pixels with yellow ones
for (int i=0; i < bMap.getHeight(); i++)
{
for(int j=0; j<bMap.getWidth(); j++)
{
iImageArray[j] = 0xFFFFFFFF;
}
}
bMap = Bitmap.createBitmap(iImageArray, bMap.getWidth(), bMap.getHeight(), Bitmap.Config.ARGB_8888);//Initialize the bitmap, with the replaced color
image.setImageBitmap(bMap);
//canvas.drawPoints(iImageArray, 0, bMap.getHeight()*bMap.getWidth(), paint);
}
});
,我想打印灰度爲此,我發現這個代碼位圖....
public Bitmap toGrayscale(Bitmap bmpOriginal)
{
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
c.drawBitmap(bmpOriginal, 0, 0, paint);
return bmpGrayscale;
}
iImageArray [i] = 0xFFFFFFFF; 我有這個測試,而不是實際的灰度值.....
謝謝:)沒有意識到......現在,如果你想打印一些延遲......假設如果添加();在iImageArray之上,整個用戶界面被延遲......如何處理這個? – jxgn 2012-02-24 03:11:36
推遲GUI線程是一個壞主意。您可以啓動一個新線程,該線程需要花時間更新位圖,然後定期通知GUI線程進行繪製(postInvalidate),以便用戶可以在動作發生時看到該動作。 – BitBank 2012-02-24 03:15:21
好吧,我現在的想法:)但我只是一個初學者,所以如果你可以給我一個例子,這將是偉大的:)謝謝:) – jxgn 2012-02-24 03:19:17