请编辑帖子把图片上传一下,感谢哦~~
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 13
targetSdkVersion 21
versionCode 2490
versionName "2.4.9"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
public class MyActivity extends Activity implements HelperCallbackInterface
{
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
// Create and set View
mView = new puzzle15View(mAppContext);
setContentView(mView);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
/** Call on every application resume **/
@Override
protected void onResume()
{
Log.i(TAG, "Called onResume");
super.onResume();
Log.i(TAG, "Trying to load OpenCV library");
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mOpenCVCallBack))
{
Log.e(TAG, "Cannot connect to OpenCV Manager");
}
}
package com.example.ras.myapplication;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import android.support.v7.app.ActionBarActivity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
Button btnProcess;
Bitmap srcBitmap;
Bitmap grayBitmap;
Bitmap MaskBitmap;
ImageView imgLena;
TextView OpCVversion;
private static final String TAG = "MainActivity";
private static boolean flag = true;
private static boolean isFirst = true; // Grey
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
// TODO Auto-generated method stub
switch (status) {
case BaseLoaderCallback.SUCCESS:
Log.i(TAG, "Load success");
break;
default:
super.onManagerConnected(status);
Log.i(TAG, "Load fail");
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
btnProcess.setOnClickListener(new ProcessClickListener());
}
public void initUI(){
btnProcess = (Button)findViewById(R.id.button);
imgLena = (ImageView)findViewById(R.id.imageView);
OpCVversion = (TextView)findViewById(R.id.textView3);
OpCVversion.setText("Ver: " + OpenCVLoader.OPENCV_VERSION_2_4_9);
Log.i(TAG, "initUI sucess...");
}
public void procSrc2Gray(){
Mat rgbMat = new Mat();
Mat grayMat = new Mat();
srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lena);
grayBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Config.RGB_565);
Utils.bitmapToMat(srcBitmap, rgbMat);//convert original bitmap to Mat, R G B.
Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY);//rgbMat to gray grayMat
Utils.matToBitmap(grayMat, grayBitmap); //convert mat to bitmap
Log.i(TAG, "procSrc2Gray sucess...");
}
private class ProcessClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(isFirst)
{
procSrc2Gray();
isFirst = false;
}
if(flag){
imgLena.setImageBitmap(grayBitmap);
btnProcess.setText("Origin");
flag = false;
}
else{
imgLena.setImageBitmap(srcBitmap);
btnProcess.setText("Grey");
flag = true;
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
//load OpenCV engine and init OpenCV library
isFirst = true;
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
Log.i(TAG, "onResume sucess load OpenCV...");
}
}
[修改于 10年1个月前 - 2014/12/22 20:17:17]
引用 1211:哦,没注意防盗链- -
请编辑帖子把图片上传一下,感谢哦~~
引用 darkorochi:最新的3.0.0beta
都2.4.9了啊。。。。。
引用 1176764177:Android应用一般用Java开发,不过C++也可以用。
这就是传说中的安卓开发环境搭建?
我查的方法得在谷歌下一堆东西必须翻墙。
咋办。。
ide用啥好用捏
c艹作为编程语言如何??
引用 1176764177:IDE可以Android Studio毕竟是谷歌官方的,也可以Intellij + ADT 也可以eclipse + ADT
这就是传说中的安卓开发环境搭建?
我查的方法得在谷歌下一堆东西必须翻墙。
咋办。。
ide用啥好用捏
c艹作为编程语言如何??
引用 4king:visual stodio好像也能开发安卓了,楼主可以试试呀
IDE可以Android Studio毕竟是谷歌官方的,也可以Intellij + ADT 也可以eclipse + ADT
也可以NDT + 别的东西
引用 张静茹:好像是英文的不知道安装在中文的vs13下会咋样
visual stodio好像也能开发安卓了,楼主可以试试呀
200字以内,仅用于支线交流,主线讨论请采用回复功能。