English 中文(简体)
对面映射发生错误时的错误
原标题:error on facedetection

作为我项目的一部分, 我正面对着以下的java 代码。

BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options();

         /*BitMapFactory-Creates Bitmap objects from various sources, including 
          * files, streams, and byte-arrays. 
          */

         BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565; 

imageWidth = myBitmap.getWidth();

     imageHeight = myBitmap.getHeight();

    myFace = new FaceDetector.Face[numberOfFace];

    myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);

     numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace); 

     }

//i get error over there in R.drawable.pics      
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pics, BitmapFactoryOptionsbfo);

I am supposed to give the name of the pic file in pics but it keeps giving me an error pics cannot be resolved or is not a field. So I set the name of the pic file as pic PS it s a jpg file in the drawable folder. I also named the file within single quotes as pic ---it gives me Invalid character constant error.

我也用双引号给它命名,但还是行不通。我还给它命名,pic.jpg仍然不起作用。

问题回答

您的代码中可能有另一个变量, 名为 pics 。

尝试将它保存在不同的文件夹中, 表示 MyPics。 并用不同的名称命名图片, 表示 xyz1. jpg

在此情况下,将行写为:

myBitmap = BitmapFactory.decodeResource(getResources(), R.MyPics.xyz1, BitmapFactoryOptionsbfo);

您是否将我的 Bitmap 初始化为位图图像? 意思是, 您是否包含此行 :

Bitmap myBitmap;

在您代码中, 执行图像读取前?

只需检查以下代码行 :

 BitmapFactory.Options options = new BitmapFactory.Options();
 options.inPreferredConfig =  Bitmap.Config RGB_565;
 Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.icon,options);

Let me know whether it works or not? Also check image names which appears after you type R.drawable.

<强度 > EDIT:

如果您仍然无法从可提取的图像访问图像, 请将图像复制到资产文件夹, 并使用以下代码访问 :

更新的代码 :

try {
       InputStream bitmap=getAssets().open("icon.png");
       Bitmap bit=BitmapFactory.decodeStream(bitmap);
       img.setImageBitmap(bit);
     } catch (IOException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签