HY !! 我想制作一个白板应用程序,但我不知道如何只制作一些黑色像素,让其他像素变白。
答案 0 :(得分:5)
这有助于在白板上获得黑色像素:
Scribbler.java:
package org.yourpackage.scribble;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class Scribbler extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
drawView.requestFocus();
}
}
DrawView.java:
package org.yourpackage.scribble;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class DrawView extends View implements OnTouchListener {
List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
for (Point point : points) {
canvas.drawCircle(point.x, point.y, 2, paint);
}
}
public boolean onTouch(View view, MotionEvent event) {
Point point = new Point();
point.x = event.getX();
point.y = event.getY();
points.add(point);
invalidate();
return true;
}
}
class Point {
float x, y;
}
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.yourpackage.scribble"
android:versionCode="1"
android:versionName="1.0">
<application>
<activity android:name=".Scribbler">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
...结果看起来像:
你可能想画线而不是像素 - 这只是为了给你一个线索
答案 1 :(得分:2)
检查一下。 http://www.tutorialforandroid.com/2009/06/drawing-with-canvas-in-android.html
此外,您可能还需要一个网络应用程序/服务,以便将屏幕内容传输给您的受众。