Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 标记“”上的语法错误;(“删除”,删除此令牌_Java_Android_Eclipse - Fatal编程技术网

Java 标记“”上的语法错误;(“删除”,删除此令牌

Java 标记“”上的语法错误;(“删除”,删除此令牌,java,android,eclipse,Java,Android,Eclipse,我正在为我去年的A-Levels开发一个应用程序,我正在尝试制作一个颜色均衡器。我可以让应用程序拍摄照片并在imageView中显示,但我似乎无法从图像中获取像素。我尝试使用“imageViewName”。getPixels或其他任何东西。getPixels但getPixels后的括号有错误“标记上的语法错误”(“,删除此标记”和结束括号中的语法错误。此处出现错误:photoViewForCrop.getPixels(像素[],x,y,imageWidth,imageHeight);非常接近代码

我正在为我去年的A-Levels开发一个应用程序,我正在尝试制作一个颜色均衡器。我可以让应用程序拍摄照片并在imageView中显示,但我似乎无法从图像中获取像素。我尝试使用“imageViewName”。getPixels或其他任何东西。getPixels但getPixels后的括号有错误“标记上的语法错误”(“,删除此标记”和结束括号中的语法错误。此处出现错误:photoViewForCrop.getPixels(像素[],x,y,imageWidth,imageHeight);非常接近代码的结尾。 这是我拍摄照片并保存到SD卡的活动,请忽略它被称为“UploadPhotoActivity”,不确定我在想什么。 代码中没有使用的导入或INT是我的老师在处理时添加的,根本没有帮助

    package com.colours.javerager;

    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;

    import android.app.ActionBar;
    import android.app.Activity;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Color;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.Toast;

    public class UploadPhotoActivity extends Activity {

//Activity request codes
private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
public static final int MEDIA_TYPE_IMAGE = 1;

//directory for file names
private static final String IMAGE_DIRECTORY_NAME = "JAverager";

private Uri fileUri; //file url to store

private ImageView photoViewForCrop;
private Button takePhotoButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload_photo);
    // Show the Up button in the action bar.
    //setupActionBar();
    ActionBar actionBar = getActionBar();
    // hide the action bar
    actionBar.hide();

    photoViewForCrop = (ImageView) findViewById(R.id.photoViewForCrop);
    takePhotoButton = (Button) findViewById(R.id.takePhotoButton);

    /**
     * Capture image button click event
     */
    takePhotoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // capture picture
            captureImage();
        }
    });

    if (!isDeviceSupportCamera()) {
        Toast.makeText(getApplicationContext(),
                "Sorry! Your device doesn't support camera",
                Toast.LENGTH_LONG).show();
        // will close the app if the device does't have camera
        finish();
    }
}
//checks if device has a camera
private boolean isDeviceSupportCamera() {
    if (getApplicationContext().getPackageManager().hasSystemFeature(
            PackageManager.FEATURE_CAMERA)) {
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}
private void captureImage() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    // start the image capture Intent
    startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // save file url in bundle as it will be null on screen orientation
    // changes
    outState.putParcelable("file_uri", fileUri);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    // get the file url
    fileUri = savedInstanceState.getParcelable("file_uri");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // if the result is capturing Image
    if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            // successfully captured the image
            // display it in image view
            previewCapturedImage();
        } else if (resultCode == RESULT_CANCELED) {
            // user cancelled Image capture
            Toast.makeText(getApplicationContext(),
                    "User cancelled image capture", Toast.LENGTH_SHORT)
                    .show();
        } else {
            // failed to capture image
            Toast.makeText(getApplicationContext(),
                    "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

/**
 * Display image from a path to ImageView
 */
private void previewCapturedImage() {
    try { 
        photoViewForCrop.setVisibility(View.VISIBLE);

        // bitmap factory
        BitmapFactory.Options options = new BitmapFactory.Options();

        // downsizing image as it throws OutOfMemory Exception for larger
        // images
        options.inSampleSize = 2;

        final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),
                options);

        photoViewForCrop.setImageBitmap(bitmap);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}
public Uri getOutputMediaFileUri(int type) {
    return Uri.fromFile(getOutputMediaFile(type));
}

/**
 * returning image 
 */
private static File getOutputMediaFile(int type) {

    // External sdcard location
    File mediaStorageDir = new File(
            Environment
                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            IMAGE_DIRECTORY_NAME);

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                    + IMAGE_DIRECTORY_NAME + " directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
            Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "JAverager_" + timeStamp + ".jpg");
    } else {
        return null;
    }

    return mediaFile;



}

int imageWidth = 640;
int imageHeight = 480;
int[] pixels = new int[307200];
int x = 1;
int y = 1;
photoViewForCrop.getPixels(pixels[], x, y, imageWidth, imageHeight);
int pixelTotal= 307200;
int valuethispixel;
int currentBlue;
int currentRed;
int currentGreen;
int totalBlue = 0;
int totalRed = 0;
int totalGreen = 0;
int currentPixel = 1;
int tempNum;
int avRed;
int avGreen;
int avBlue;

{



while(1 < pixelTotal){
    tempNum = (Integer) pixels[currentPixel];
    currentBlue = Color.blue(tempNum);
    currentRed = Color.red(tempNum);
    currentGreen = Color.green(tempNum);
    totalBlue = totalBlue + currentBlue;
    totalRed = totalRed + currentRed;
    totalGreen = totalGreen + currentGreen;
    currentPixel = currentPixel + 1;
}

totalBlue = totalBlue / pixelTotal;
totalRed = totalRed / pixelTotal;
totalGreen = totalGreen / pixelTotal;

}
    };
package com.colors.javerager;
导入java.io.File;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入java.util.Locale;
导入android.app.ActionBar;
导入android.app.Activity;
导入android.content.Intent;
导入android.content.pm.PackageManager;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Color;
导入android.net.Uri;
导入android.os.Bundle;
导入android.os.Environment;
导入android.provider.MediaStore;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.ImageView;
导入android.widget.Toast;
公共类UploadPhotoActivity扩展活动{
//活动请求代码
专用静态最终int摄像机\捕获\图像\请求\代码=100;
公共静态最终int媒体类型图像=1;
//文件名目录
私有静态最终字符串IMAGE\u DIRECTORY\u NAME=“JAverager”;
私有Uri fileUri;//要存储的文件url
private ImageView Photoview for Crop;
私人按钮;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u upload\u photo);
//在操作栏中显示“向上”按钮。
//setupActionBar();
ActionBar ActionBar=getActionBar();
//隐藏操作栏
actionBar.hide();
photoViewForCrop=(ImageView)findViewById(R.id.photoViewForCrop);
takePhotoButton=(按钮)findViewById(R.id.takePhotoButton);
/**
*捕获图像按钮单击事件
*/
takePhotoButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//截图
captureImage();
}
});
如果(!isDeviceSupportCamera()){
Toast.makeText(getApplicationContext(),
“抱歉!您的设备不支持摄像头”,
Toast.LENGTH_LONG).show();
//如果设备没有摄像头,将关闭应用程序
完成();
}
}
//检查设备是否有摄像头
专用布尔值isDeviceSupportCamera(){
如果(getApplicationContext().getPackageManager().hasSystemFeature(
包装管理器功能(摄像头){
//这个装置有一个照相机
返回true;
}否则{
//此设备上没有摄像头
返回false;
}
}
私有void captureImage(){
意向意向=新意向(MediaStore.ACTION\u IMAGE\u CAPTURE);
fileUri=getOutputMediaFileUri(媒体类型图像);
intent.putExtra(MediaStore.EXTRA_输出,fileUri);
//启动图像捕获计划
startActivityForResult(意图、摄像头捕捉、图像、请求、代码);
}
@凌驾
SaveInstanceState上受保护的无效(束超出状态){
super.onSaveInstanceState(超出状态);
//将文件url保存在捆绑包中,因为它在屏幕上为空
//变化
outState.putParcelable(“file_uri”,fileUri);
}
@凌驾
RestoreInstanceState上的受保护无效(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
//获取文件url
fileUri=savedInstanceState.getParcelable(“文件uri”);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
//如果结果是捕获图像
if(requestCode==摄像机捕捉图像请求代码){
if(resultCode==RESULT\u OK){
//成功捕获图像
//在图像视图中显示它
previewCapturedImage();
}else if(resultCode==RESULT\u取消){
//用户取消图像捕获
Toast.makeText(getApplicationContext(),
“用户已取消图像捕获”,Toast.LENGTH\u SHORT)
.show();
}否则{
//未能捕获图像
Toast.makeText(getApplicationContext(),
“抱歉!未能捕获图像”,Toast.LENGTH\u SHORT)
.show();
}
}
}
/**
*显示从路径到ImageView的图像
*/
私有void previewCapturedImage(){
试试{
photoViewForCrop.setVisibility(View.VISIBLE);
//位图工厂
BitmapFactory.Options=new-BitmapFactory.Options();
//缩小图像,因为它会抛出较大的内存异常
//图像
options.inSampleSize=2;
最终位图位图=位图工厂.decodeFile(fileUri.getPath(),
选择权);
photoViewForCrop.setImageBitmap(位图);
}捕获(NullPointerException e){
e、 printStackTrace();
}
}
公共Uri getOutputMediaFileUri(int类型){
返回Uri.fromFile(getOutputMediaFile(类型));
}
/**
*返回图像
*/
私有静态文件getOutputMediaFile(int类型){
//外部SD卡位置
File mediaStorageDir=新文件(
环境
.getExternalStoragePublicDirectory(Environment.DIRECTORY\u图片),
图像\目录\名称);
//如果存储目录不存在,请创建该目录
如果(!mediaSt