我正在尝试实现此代码:
package fortyonepost.com.iapa;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
public class ImageAsPixelArray extends Activity
{
//a Bitmap that will act as a handle to the image
private Bitmap bmp;
//an integer array that will store ARGB pixel values
private int[][] rgbValues;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//load the image and use the bmp object to access it
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);
//define the array size
rgbValues = new int[bmp.getWidth()][bmp.getHeight()];
//Print in LogCat's console each of one the RGB and alpha values from the 4 corners of the image
//Top Left
Log.i("Pixel Value", "Top Left pixel: " + Integer.toHexString(bmp.getPixel(0, 0)));
//Top Right
Log.i("Pixel Value", "Top Right pixel: " + Integer.toHexString(bmp.getPixel(31, 0)));
//Bottom Left
Log.i("Pixel Value", "Bottom Left pixel: " + Integer.toHexString(bmp.getPixel(0, 31)));
//Bottom Right
Log.i("Pixel Value", "Bottom Right pixel: " + Integer.toHexString(bmp.getPixel(31, 31)));
//get the ARGB value from each pixel of the image and store it into the array
for(int i=0; i < bmp.getWidth(); i++)
{
for(int j=0; j < bmp.getHeight(); j++)
{
//This is a great opportunity to filter the ARGB values
rgbValues[i][j] = bmp.getPixel(i, j);
}
}
//Do something with the ARGB value array
}
}
}
我似乎无法弄清楚这行代码做了什么 bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);
当我尝试实现它时,eclipse 会说它找不到four_colors 是什么,我不知道它是什么并且似乎无法弄清楚。小伙伴们知道是什么吗?以及应该如何使用?预先感谢