在令牌QUOT语法错误;(&QUOT ;,删除此令牌 [英] Syntax error on token "(", delete this token

查看:211
本文介绍了在令牌QUOT语法错误;(&QUOT ;,删除此令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序为我的A-水平的去年,我试图使一个颜色平均器。我可以让应用程序拍摄照片并在ImageView的显示,但我似乎无法获得图像的像素。我一直在使用imageViewName.getPixels或其他任何.getPixels但括号尝试后的getPixels有错误(删除此令牌和同为端支架上标记语法错误。

出现错误在这里:

photoViewForCrop.getPixels(像素[],X,Y,imageWidth,imageHeight);

这是相当接近code的结束。

下面是我的活动,拍摄照片并将其保存到SD卡上,请忽略这就是所谓的'UploadPhotoActivity',不知道我在想什么。

是由我的老师补充说,没有在code采用进口或者整形时,他与它搞乱,而不是帮助都没有。

 包com.colours.javerager;    进口的java.io.File;
    进口java.text.SimpleDateFormat的;
    进口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延伸活动{//活动要求codeS
私有静态最终诠释CAMERA_CAPTURE_IMAGE_REQUEST_ code = 100;
公共静态最终诠释MEDIA_TYPE_IMAGE = 1;//目录文件名
私有静态最后弦乐IMAGE_DIRECTORY_NAME =JAverager;私人乌里了fileURI; // URL文件来存储私人ImageView的photoViewForCrop;
私人按钮takePhotoButton;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_upload_photo);
    //显示操作栏中的向上按钮。
    // setupActionBar();
    动作条动作条= getActionBar();
    //隐藏操作栏
    actionBar.hide();    photoViewForCrop =(ImageView的)findViewById(R.id.photoViewForCrop);
    takePhotoButton =(按钮)findViewById(R.id.takePhotoButton);    / **
     *捕获图像按钮单击事件
     * /
    takePhotoButton.setOnClickListener(新View.OnClickListener(){        @覆盖
        公共无效的onClick(视图v){
            //捕捉画面
            captureImage();
        }
    });    如果(!isDeviceSupportCamera()){
        Toast.makeText(getApplicationContext(),
                对不起!您的设备不支持摄像头
                Toast.LENGTH_LONG).show();
        //如果设备有简化版,相机将关闭该应用程序
        完();
    }
}
//检查设备有一个摄像头
私人布尔isDeviceSupportCamera(){
    如果(getApplicationContext()。getPackageManager()。hasSystemFeature(
            PackageManager.FEATURE_CAMERA)){
        //这个设备有一个摄像头
        返回true;
    }其他{
        //此设备上没有摄像头
        返回false;
    }
}
私人无效captureImage(){
    意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);    了fileURI = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);    intent.putExtra(MediaStore.EXTRA_OUTPUT,fileURI所);    //启动图像拍摄意图
    startActivityForResult(意向,CAMERA_CAPTURE_IMAGE_REQUEST_ code);
}
@覆盖
保护无效的onSaveInstanceState(捆绑outState){
    super.onSaveInstanceState(outState);    //保存包文件URL时,它会在屏幕方向空
    //改变
    outState.putParcelable(file_uri了fileURI);
}@覆盖
保护无效onRestoreInstanceState(捆绑savedInstanceState){
    super.onRestoreInstanceState(savedInstanceState);    //获取文件的URL
    了fileURI = savedInstanceState.getParcelable(file_uri);
}
@覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    //如果结果是捕获的图像
    如果(要求code == CAMERA_CAPTURE_IMAGE_REQUEST_ code){
        如果(结果code == RESULT_OK){
            //成功地拍摄的图像
            //图像视图中显示它
            previewCapturedImage();
        }否则如果(结果code == RESULT_CANCELED){
            //用户取消图像采集
            Toast.makeText(getApplicationContext(),
                    用户已取消图像捕捉,Toast.LENGTH_SHORT)
                    。显示();
        }其他{
            //未能捕捉到的图像
            Toast.makeText(getApplicationContext(),
                    对不起!无法捕捉到的图像,Toast.LENGTH_SHORT)
                    。显示();
        }
    }
}/ **
 *从显示到ImageView的路径图像
 * /
私人无效previewCapturedImage(){
    尝试{
        photoViewForCrop.setVisibility(View.VISIBLE);        //位图厂
        BitmapFactory.Options选项=新BitmapFactory.Options();        //瘦身的图像,因为它会引发较大的内存不足异常
        //图片
        options.inSampleSize = 2;        最后的位图位图= BitmapFactory.de codeFILE(fileUri.getPath()
                选项​​);        photoViewForCrop.setImageBitmap(位图);
    }赶上(NullPointerException异常五){
        e.printStackTrace();
    }
}
公共乌里getOutputMediaFileUri(整型){
    返回Uri.fromFile(getOutputMediaFile(类型));
}/ **
 *返回图像
 * /
私有静态文件getOutputMediaFile(整型){    //外接SD卡的位置
    文件mediaStorageDir =新的文件(
            环境
                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
            IMAGE_DIRECTORY_NAME);    //创建存储目录,如果它不存在
    如果(!mediaStorageDir.exists()){
        如果(!mediaStorageDir.mkdirs()){
            Log.d(IMAGE_DIRECTORY_NAME,哎呀!失败创造
                    + IMAGE_DIRECTORY_NAME +目录);
            返回null;
        }
    }    //创建一个媒体文件名
    字符串的timeStamp =新的SimpleDateFormat(YYYYMMDD_HHMMSS
            。Locale.getDefault())格式(新的Date());
    文件媒体文件;
    如果(类型== MEDIA_TYPE_IMAGE){
        媒体文件=新的文件(mediaStorageDir.getPath()+文件分割符
                +JAverager_+ +的timeStamp.JPG);
    }其他{
        返回null;
    }    返回媒体文件;}INT imageWidth = 640;
INT imageHeight = 480;
INT [] =像素新INT [307200]。
INT X = 1;
INT Y = 1;
photoViewForCrop.getPixels(像素[],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;{而(1 <<; pixelTotal){
    tempNum =(整数)像素[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;}
    };


解决方案

一切后getOutputMediaFile方法不是一种方法里面,这就是为什么你的方法调用,之后while循环定义将无法正常工作

I'm working on an app for my last year of A-Levels and I'm trying to make a colour averager. I can make the app take the picture and display it in an imageView but I can't seem to get the pixels from the image. I've tried using "imageViewName".getPixels or anything else .getPixels but the brackets after getPixels have the error "Syntax error on token "(", delete this token" and the same for the end bracket.

The error occurs here:

photoViewForCrop.getPixels(pixels[], x, y, imageWidth, imageHeight);

Which is quite close to the end of the code.

Here's my activity that takes the photo and saves it to the SD card, please ignore that it's called 'UploadPhotoActivity', not sure what I was thinking.

Imports or ints that aren't used in the code were added by my teacher when he was messing with it and not helping at all.

    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;

}
    };

解决方案

everything after the getOutputMediaFile method is not inside a method, thats why your method call and after that the while loop definition won't work

这篇关于在令牌QUOT语法错误;(&QUOT ;,删除此令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆