我想實現這個代碼:BitmapFactory.decodeResource(getResources(),R.drawable.four_colors); four_colors是什麼意思?
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);
當我嘗試實現它,日食會說找不到four_colors是什麼,但我沒有任何知道它是什麼和不能似乎弄明白。 你們知道它是什麼嗎?它應該如何使用? 提前致謝
確定,所以它實際上是照片即時通訊試圖analize?那麼如果它應該分析我剛剛拍攝的照片,我應該通過照片的路徑?我怎樣才能做到這一點?非常感謝! – oskar132
您需要使用BitmapFactory上的其他方法之一,如decodeFile。資源已內置到您的應用程序中。 –