简体   繁体   English

BitmapFactory.decodeResource(getResources(),R.drawable.four_colors); four_colors是什么意思?

[英]BitmapFactory.decodeResource(getResources(), R.drawable.four_colors); what does four_colors mean?

I am trying to implement this code: 我正在尝试实现以下代码:

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  
}  
}  

}

I can't seem to figure out what this line of code does bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors); 我似乎无法弄清楚这行代码是做什么的bmp = BitmapFactory.decodeResource(getResources(),R.drawable.four_colors);
when i try to implement it, eclipse will say it can't find what four_colors is, i've got no idea what it is and cant seem to figure it out. 当我尝试实现它时,eclipse会说它找不到four_colors是什么,我不知道它是什么并且似乎无法弄清楚。 Do you guys know what it is? 你们知道这是什么吗? and how should it be used? 以及如何使用? thank in advance 预先感谢

R is an automatically generated file that keeps track of the resources in your project. R是自动生成的文件,用于跟踪项目中的资源。 The drawable means the resource is of the type drawable, usually (but not always) meaning the resource is in one of your res/drawables -folders, eg res/drawables_xhdpi . drawable表示资源属于可绘制类型,通常(但并非总是)表示资源位于您的res/drawables夹之一中,例如res/drawables_xhdpi Four_colors refers to the resource name, usually indicating the file you're referring to is a file called 'four_colors` (eg a PNG-file) in eg the res/drawables-xhdpi folder. Four_colors指的是资源名称,通常表示您所指的文件是res / drawables-xhdpi文件夹中的一个名为“ four_colors”的文件(例如PNG文件)。

So, the four_colors refers to the name of the (in this case) drawable your app trying to load. 因此,four_colors表示您尝试加载的应用程序(在这种情况下)可绘制的名称。

When Eclipse says it cannot find the resource, it means the resource is not included in the project where it should be included. 当Eclipse表示找不到资源时,表示该资源未包含在应包含该项目的项目中。 Eg you copied some code, but not the drawables that are referred to in the code. 例如,您复制了一些代码,但没有复制代码中引用的可绘制对象。

The line BitmapFactory.decodeResource(...) does exactly what it says; BitmapFactory.decodeResource(...)行完全按照其说的进行; it decodes the encoded image into a bitmap, something Android can actually show. 它将编码的图像解码为位图,Android可以实际显示出来。 Usually when you use bitmaps it does this kind of decoding under the hood; 通常,当您使用位图时,它会在后台进行这种解码。 here it's done manually. 在这里,它是手动完成的。

You'll need to download this image and put it in your ./res/drawable folder. 您需要下载图像并将其放在./res/drawable文件夹中。 Be sure to right click the project and select refresh. 确保右键单击该项目,然后选择刷新。

four_colors is the name of the image. four_colors是图像的名称。 you have to place image in res / drawable image should have name four_colors.jpg 您必须将图像放置在res /可绘制图像中,其名称应为four_colors.jpg

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何插入四种颜色? - How to interpolate four colors? 为什么我不能在实用程序类(不是活动的类)中使用BitmapFactory.decodeResource()方法?无法解析方法getResources() - Why I can't use the BitmapFactory.decodeResource() metod into an utility class (a class that is not an activity)?Cannot resolve method getResources() BitmapFactory.decodeResource在Android 2.2上为null - BitmapFactory.decodeResource gives null on Android 2.2 BitmapFactory.decodeResource或解码流用于不同的图像 - BitmapFactory.decodeResource or decodeStream for different images 为什么使用inPreferredConfig = RGB565的BitmapFactory.decodeResource可以按比例放大我的图片x2? - Why does BitmapFactory.decodeResource with inPreferredConfig=RGB565 scale up my pictures x2? 平均四个像素的图像会产生闪烁的颜色 - Averaging four pixels of image yields wonky colors Android BitmapFactory.decodeResource需要太多内存 - Android BitmapFactory.decodeResource takes too much memory 在RecyclerView的ViewHolder内的BitmapFactory.decodeResource中找不到getresource - Not finding getresource in BitmapFactory.decodeResource inside ViewHolder in RecyclerView 四种颜色的荷兰国旗算法 - Dutch national flag algorithm with four colors BitmapFactory.decodeResource 在 Android 2.2 中返回可变位图,在 Android 1.6 中返回不可变位图 - BitmapFactory.decodeResource returns a mutable Bitmap in Android 2.2 and an immutable Bitmap in Android 1.6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM