- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现此代码:
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 是什么,我不知道它是什么并且似乎无法弄清楚。你们知道那是什么吗?以及应该如何使用它?提前致谢
最佳答案
R 是一个自动生成的文件,用于跟踪项目中的资源。可绘制意味着资源属于可绘制类型,通常(但并非总是)意味着资源位于您的 res/drawables
文件夹之一中,例如res/drawables_xhdpi
。 four_colors 指的是资源名称,通常表示您所引用的文件是名为“four_colors”的文件(例如 PNG 文件),例如res/drawables-xhdpi 文件夹。
因此,four_colors 指的是您的应用尝试加载的(在本例中)可绘制对象的名称。
当 Eclipse 说找不到资源时,这意味着该资源没有包含在应包含的项目中。例如。您复制了一些代码,但没有复制代码中引用的可绘制对象。
BitmapFactory.decodeResource(...)
行的作用与它所说的完全一样;它将编码的图像解码为位图,这是 Android 可以实际显示的。通常,当您使用位图时,它会在幕后进行这种解码;这里是手动完成的。
关于java - BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);四色是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12451112/
在我的应用程序中,我有以下几行代码: import android.graphics.Bitmap; import android.graphics.BitmapFactory; private Bi
我有这种方法,可以在图像上绘制一些文本: public BitmapDrawable writeOnDrawable(int drawableId, String text){ Bit
我正在尝试从 View 对象中的内部资源加载位图(源本身位于“可绘制”文件中)。 代码是: import android.content.Context; import android.graphic
我正在为 child 子开发一款游戏,其中包含不同的教育练习。在其中一个中,我需要一个图片背景,因此我正在加载它并使用矩阵缩放它以填充屏幕。但有时加载图片会导致崩溃。 public DrawThrea
我正在重新编写一个 Android 应用程序,其中每个 Activity (有多个)都显示背景图片。用户可能会更改此图像,因此我已完成以下操作: 创建了 MyAppApplication(扩展了 Ap
您好,我正在使用以下方法将位图设置为 ImageView: o = new BitmapFactory.Options(); o.inJustDecodeBounds
我的 /res/drawable/ 目录中有一张 120x120px 的图片。这是所有设备所需的大小。 要加载此位图,我使用以下内容: Bitmap tmpBmp = BitmapFactory.de
我刚刚在检查一些资源图像的一些解码时间时注意到,当我将资源图像移动到 drawable 文件夹时,BitmapFactory.decodeResource() 函数大约慢了 3-6 倍。 问题: 有人
我对从资源加载位图有疑问。我的代码: public void onClick(View view) { if (mainButton == view) { Bitmap bm
我有这段代码可以裁剪图像表的一部分。 问题是当我使用 BitmapFactory.decodeResource 并记录宽度和高度时,大小与原始大小不同。 Bitmap spriteSheet = Bi
我的 /res/drawable/ 目录中有一张 120x120px 的图片。这是所有设备所需的大小。 要加载此位图,我使用以下内容: Bitmap tmpBmp = BitmapFactory.de
我在解码可绘制图像资源 960x926px jpg 时遇到奇怪的内存不足错误,分配了 3555856 字节。图像仅放置在 drawable-xxhdpi (3x) 中,我使用的是 hdpi (1.5x
我似乎无法弄清楚这一点。我有 2 个具有不同特性的 java 类,每个都调用 BitmapFactory.decodeResource 来获取相同的图像资源,一个返回位图,而另一个返回 null。这两
我正在尝试从文件夹/drawable 中获取图像,但当 api > 19 时我收到 null。有人知道问题出在哪里吗? 我使用的所有图像都是矢量。 dog.setImagen(BitmapFactor
我想得到 image在我的 bitmap像这样: bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bug); 但这显示
我尝试在我的 Activity 中使用类 BitmapFactory 中的 decodeResource 方法,如下所示: Bitmap image = new BitmapFactory.decod
我已经检查了所有其他类似的问题,但没有人帮助我。这是我获取位图的代码: public class HachureView extends View { //... @Override
打电话是不是不好的做法 getResources().getDrawable() 或 BitmapFactory.decodeResource() 来自 Android 上的 UI 线程?我只是想知道
我想知道 decodeResource (Resources res, int id, BitmapFactory.Options opts) 是否考虑了 drawable-ldpi、mdpi、hdp
在我当前的 android 项目中,我从 xml 资源创建了两个位图。每次我使用 xml 位图作为 Bitmap.decodeResources() 的资源构建我的项目时,当我尝试访问位图时,我都会遇
我是一名优秀的程序员,十分优秀!