我不知道为什么会出现此消息...应用程序可以正常打开,但是一旦我更改了应用程序中的搜索栏,消息就会弹出并停止运行。
我正在使用空白活动,并发布了.xml和.java文件。请回复。
linearlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="R" />
<SeekBar
android:id="@+id/sb_red"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:progress="128" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="G" />
<SeekBar
android:id="@+id/sb_green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:progress="128" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
<SeekBar
android:id="@+id/sb_blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:progress="128" />
<ImageView
android:id="@+id/iv_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/game" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rohit2906.rgbvalues" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.rohit2906.rgbvalues;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
public class MainActivity extends Activity {
private SeekBar sb_red, sb_green, sb_blue;
private ImageView iv_show;
private Bitmap afterBitmap;
private Paint paint;
private Canvas canvas;
private Bitmap baseBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linearlayout);
iv_show = (ImageView) findViewById(R.id.iv_show);
sb_red = (SeekBar) findViewById(R.id.sb_red);
sb_green = (SeekBar) findViewById(R.id.sb_green);
sb_blue = (SeekBar) findViewById(R.id.sb_blue);
sb_red.setOnSeekBarChangeListener(seekBarChange);
sb_green.setOnSeekBarChangeListener(seekBarChange);
sb_blue.setOnSeekBarChangeListener(seekBarChange);
// Get a picture from a resource file
baseBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.game);
// Empty picture gets a and baseBitmap the same size editable
afterBitmap = Bitmap.createBitmap(baseBitmap.getWidth(),
baseBitmap.getHeight(), baseBitmap.getConfig());
canvas = new Canvas(afterBitmap);
paint = new Paint();
}
private SeekBar.OnSeekBarChangeListener seekBarChange = new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Gets the current value of each SeekBar
float progressR = sb_red.getProgress()/128f;
float progressG = sb_green.getProgress()/128f;
float progressB = sb_blue.getProgress()/128f;
Log.i("main", "R: G: B="+progressR+": "+progressG+": "+progressB);
// According to the definition of the RGB matrix SeekBar
float[] src = new float[]{
progressR, 0, 0, 0, 0,
0, progressG, 0, 0, 0,
0, 0, progressB, 0, 0,
};
// The definition of ColorMatrix, and specify the RGB matrix
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(src);
// Set the Paint color
paint.setColorFilter(new ColorMatrixColorFilter(src));
// By specifying the RGB matrix Paint of the original picture of the blank picture
canvas.drawBitmap(baseBitmap, new Matrix(), paint);
iv_show.setImageBitmap(afterBitmap);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
}
};
}
日志猫
02-22 15:45:37.334 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Not late-enabling -Xcheck:jni (already on)
02-22 15:45:38.684 1768-1780/com.example.rohit2906.rgbvalues I/art﹕ Background sticky concurrent mark sweep GC freed 7(272B) AllocSpace objects, 0(0B) LOS objects, 0% free, 26MB/26MB, paused 33.108ms total 56.416ms
02-22 15:45:38.804 1768-1804/com.example.rohit2906.rgbvalues D/OpenGLRenderer﹕ Render dirty regions requested: true
02-22 15:45:38.806 1768-1768/com.example.rohit2906.rgbvalues D/﹕ HostConnection::get() New Host Connection established 0xae0d2dc0, tid 1768
02-22 15:45:38.810 1768-1768/com.example.rohit2906.rgbvalues D/Atlas﹕ Validating map...
02-22 15:45:38.970 1768-1804/com.example.rohit2906.rgbvalues D/﹕ HostConnection::get() New Host Connection established 0xae0d2f00, tid 1804
02-22 15:45:38.972 1768-1804/com.example.rohit2906.rgbvalues I/OpenGLRenderer﹕ Initialized EGL, version 1.4
02-22 15:45:39.117 1768-1804/com.example.rohit2906.rgbvalues D/OpenGLRenderer﹕ Enabling debug mode 0
02-22 15:45:39.245 1768-1804/com.example.rohit2906.rgbvalues W/EGL_emulation﹕ eglSurfaceAttrib not implemented
02-22 15:45:39.245 1768-1804/com.example.rohit2906.rgbvalues W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6c8d660, error=EGL_SUCCESS
02-22 15:45:41.195 1768-1768/com.example.rohit2906.rgbvalues I/Choreographer﹕ Skipped 108 frames! The application may be doing too much work on its main thread.
02-22 15:46:16.236 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 3% free, 53MB/55MB, paused 1.103ms total 18.769ms
02-22 15:46:16.252 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc partial concurrent mark sweep GC freed 201(9KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 1.110ms total 16.307ms
02-22 15:46:16.272 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc concurrent mark sweep GC freed 8(12KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 11.662ms total 18.752ms
02-22 15:46:16.272 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Forcing collection of SoftReferences for 13MB allocation
02-22 15:46:16.344 1768-1768/com.example.rohit2906.rgbvalues I/art﹕ Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 879us total 71.595ms
02-22 15:46:16.344 1768-1768/com.example.rohit2906.rgbvalues E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 13824012 byte allocation with 4194304 free bytes and 10MB until OOM"
02-22 15:46:16.344 1768-1768/com.example.rohit2906.rgbvalues D/AndroidRuntime﹕ Shutting down VM
--------- beginning of crash
02-22 15:46:16.345 1768-1768/com.example.rohit2906.rgbvalues E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.rohit2906.rgbvalues, PID: 1768
java.lang.OutOfMemoryError: Failed to allocate a 13824012 byte allocation with 4194304 free bytes and 10MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:817)
at android.graphics.Bitmap.createBitmap(Bitmap.java:794)
at android.graphics.Bitmap.createBitmap(Bitmap.java:761)
at com.example.rohit2906.rgbvalues.MainActivity.onCreate(MainActivity.java:46)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3912)
at android.app.ActivityThread.access$900(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
您忘记了src
数组中的Alpha线。
代替:
float[] src = new float[]{
progressR, 0, 0, 0, 0,
0, progressG, 0, 0, 0,
0, 0, progressB, 0, 0,
};
有了这个:
float[] src = new float[]{
progressR, 0, 0, 0, 0, //Red
0, progressG, 0, 0, 0, //Green
0, 0, progressB, 0, 0, //Blue
0, 0, 0, 1, 0, //alpha
};
set(float[])
在ColorMatrix
对象上调用方法时,如以下代码所示:
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(src);
您会收到异常,并且应用程序崩溃了。所述src
阵列必须是相同的长度在阵列ColorMartix
对象。它必须有20个长度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句