Re: [android-developers] Canvas or Gesture??

2012-08-16 Thread John Archer
Thanks all for the efforts Robin  et. al.,

I am trying to so something very similar - create a signature page.

Did you figure what was missing to get the erase and properly saved image 
here?

thanks
john


On Wednesday, February 16, 2011 1:17:15 PM UTC-6, Robin Talwar wrote:

 Alright

 So now i have 2 classes in my application.
 the one is the custom view extending view and has all touch events on key 
 down and on key up.
 This view is being called in my main.xml through the package name.
 The other one is my main class which has the code to call options menu.
 One menu item is Save and if user clicks on it the bitmap image created by 
 the custom view is to be saved .
 It is actually getting saved but it is showing just the background not the 
 changed bitmap image through the touch of the user.

 The custom view code is exactly the same as the FingerPaint class file in 
 api demos 

 The only thing where i am getting stuck is now how to save the changed 
 bitmap image which is created by the users touch i can save the initial one 

 The code of main class file is :-
 package org.testCircle;

 import android.app.Activity;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.os.Bundle;
 import android.provider.MediaStore.Images;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.widget.TextView;
 import android.widget.Toast;

 public class testCircle extends Activity {
 TextView tv;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 //setContentView(new customView(this));
 setContentView(R.layout.main);
 }
 public boolean onCreateOptionsMenu(Menu menu) {
 super.onCreateOptionsMenu(menu);
 
 menu.add(0, 1, 0, save).setShortcut('3', 'c');
 return true;
 }
 public boolean onPrepareOptionsMenu(Menu menu) {
 super.onPrepareOptionsMenu(menu);
 return true;
 }
 
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
 switch (item.getItemId()) {
 case 1:
 //new ColorPickerDialog(this, this, mPaint.getColor()).show();
 fingerPaint cv = new fingerPaint(this);
 Bitmap viewBitmap = Bitmap.createBitmap(cv.getWidth(), 
 cv.getHeight(),Bitmap.Config.ARGB_);
 Canvas canvas = new Canvas(viewBitmap);
 cv.draw(canvas);
 String url = Images.Media.insertImage(getContentResolver(), 
 viewBitmap, title, null);
 Toast.makeText(testCircle.this, url, Toast.LENGTH_LONG).show();
 return true;
 }
 return super.onOptionsItemSelected(item);
 }
 }


 and the Custom View is 

 package org.testCircle;

 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;

 public class fingerPaint extends View {
 Paint mPaint;
 
 private static final float MINP = 0.25f;
 private static final float MAXP = 0.75f;
 
 private static Bitmap  mBitmap;
 private Canvas  mCanvas;
 private PathmPath;
 private Paint   mBitmapPaint;
 
 public fingerPaint(Context c) {
 super(c);
 mPaint = new Paint();
 mPaint.setAntiAlias(true);
 mPaint.setDither(true);
 mPaint.setColor(0x);
 mPaint.setStyle(Paint.Style.STROKE);
 mPaint.setStrokeJoin(Paint.Join.ROUND);
 mPaint.setStrokeCap(Paint.Cap.ROUND);
 mPaint.setStrokeWidth(12);
 mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_);
 mCanvas = new Canvas(mBitmap);
 mPath = new Path();
 mBitmapPaint = new Paint(Paint.DITHER_FLAG);
 }
 
 public fingerPaint(Context c , AttributeSet attrs){
 super(c , attrs);
  mPaint = new Paint();
  mPaint.setAntiAlias(true);
  mPaint.setDither(true);
  mPaint.setColor(0x);
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  mPaint.setStrokeCap(Paint.Cap.ROUND);
  mPaint.setStrokeWidth(12);
  mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_);
  mCanvas = new Canvas(mBitmap);
  mPath = new Path();
  mBitmapPaint = new Paint(Paint.DITHER_FLAG);
 }
 
 public void onerase(){
 mCanvas=null;
 }

 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
 super.onSizeChanged(w, h, oldw, oldh);
 }
 
 @Override
 protected void onDraw(Canvas canvas) {
 canvas.drawColor(0xFFAA);
 
 canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
 
 

Re: [android-developers] Canvas or Gesture??

2011-02-16 Thread Robin Talwar
On Tue, Feb 15, 2011 at 6:35 PM, Marcin Orlowski
webnet.andr...@gmail.comwrote:

 On 15 February 2011 13:10, Robin Talwar r.o.b.i.n.abhis...@gmail.com
 wrote:

  Saving this bitmap and

 String path = Environment.getExternalStorageDirectory().toString();
 OutputStream fOut = new FileOutputStream( new File(path, filename.jpg) );
 bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
 fOut.flush();
 fOut.close();

  Erase button to clear all the canvas so that user can again make
 signature
  on clear screen.


 http://developer.android.com/reference/android/graphics/Canvas.html#drawRGB%28int,%20int,%20int%29

 but again: do RTFM first as there are other options you may want to
 utilse (i.e. you may want to save as PNG instead of lossy JPEG) or
 simply to know whene you will be trying to reinvent the wheel.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Canvas or Gesture??

2011-02-16 Thread Robin Talwar
Alright

So now i have 2 classes in my application.
the one is the custom view extending view and has all touch events on key
down and on key up.
This view is being called in my main.xml through the package name.
The other one is my main class which has the code to call options menu.
One menu item is Save and if user clicks on it the bitmap image created by
the custom view is to be saved .
It is actually getting saved but it is showing just the background not the
changed bitmap image through the touch of the user.

The custom view code is exactly the same as the FingerPaint class file in
api demos

The only thing where i am getting stuck is now how to save the changed
bitmap image which is created by the users touch i can save the initial one

The code of main class file is :-
package org.testCircle;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class testCircle extends Activity {
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(new customView(this));
setContentView(R.layout.main);
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

menu.add(0, 1, 0, save).setShortcut('3', 'c');
return true;
}
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
//new ColorPickerDialog(this, this, mPaint.getColor()).show();
fingerPaint cv = new fingerPaint(this);
Bitmap viewBitmap = Bitmap.createBitmap(cv.getWidth(),
cv.getHeight(),Bitmap.Config.ARGB_);
Canvas canvas = new Canvas(viewBitmap);
cv.draw(canvas);
String url = Images.Media.insertImage(getContentResolver(),
viewBitmap, title, null);
Toast.makeText(testCircle.this, url, Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}


and the Custom View is

package org.testCircle;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class fingerPaint extends View {
Paint mPaint;

private static final float MINP = 0.25f;
private static final float MAXP = 0.75f;

private static Bitmap  mBitmap;
private Canvas  mCanvas;
private PathmPath;
private Paint   mBitmapPaint;

public fingerPaint(Context c) {
super(c);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0x);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(12);
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}

public fingerPaint(Context c , AttributeSet attrs){
super(c , attrs);
 mPaint = new Paint();
 mPaint.setAntiAlias(true);
 mPaint.setDither(true);
 mPaint.setColor(0x);
 mPaint.setStyle(Paint.Style.STROKE);
 mPaint.setStrokeJoin(Paint.Join.ROUND);
 mPaint.setStrokeCap(Paint.Cap.ROUND);
 mPaint.setStrokeWidth(12);
 mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_);
 mCanvas = new Canvas(mBitmap);
 mPath = new Path();
 mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}

public void onerase(){
mCanvas=null;
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
}

@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAA);

canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

canvas.drawPath(mPath, mPaint);
}

private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx = TOUCH_TOLERANCE || dy = TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + 

Re: [android-developers] Canvas or Gesture??

2011-02-15 Thread Marcin Orlowski
On 14 February 2011 21:40, Robin Talwar r.o.b.i.n.abhis...@gmail.com wrote:

 Is that all possible? can i convert a gesture into an image?

No. But you can paint on your canvase based on user gestures or touches.
I'd suggest you read some basics on what canvas, paint, bitmap is and what
they do offer and then read on GestureDetector and motionEvents your
listener will get. Then you (assuming it's not goint to be your first app ever)
shall get the picture on what you get as input and how you can use it.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Canvas or Gesture??

2011-02-15 Thread Robin Talwar
Ya this is not my first application , i have done some media streaming ,
played with database , web services so if guided will not
take much time to make this application.
I am now looking into api demo's FingerPaint application.
I can now give the touch paint facility so that user can touch the screen
and drag the finger in whicheva shape and create whatever. Basically user
can now make a signature but two things which are lacking are :-

Saving this bitmap and
Erase button to clear all the canvas so that user can again make signature
on clear screen.



On Tue, Feb 15, 2011 at 5:09 PM, Marcin Orlowski
webnet.andr...@gmail.comwrote:

 On 14 February 2011 21:40, Robin Talwar r.o.b.i.n.abhis...@gmail.com
 wrote:

  Is that all possible? can i convert a gesture into an image?

 No. But you can paint on your canvase based on user gestures or touches.
 I'd suggest you read some basics on what canvas, paint, bitmap is and what
 they do offer and then read on GestureDetector and motionEvents your
 listener will get. Then you (assuming it's not goint to be your first app
 ever)
 shall get the picture on what you get as input and how you can use it.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Canvas or Gesture??

2011-02-15 Thread Marcin Orlowski
On 15 February 2011 13:10, Robin Talwar r.o.b.i.n.abhis...@gmail.com wrote:

 Saving this bitmap and

String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = new FileOutputStream( new File(path, filename.jpg) );
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();

 Erase button to clear all the canvas so that user can again make signature
 on clear screen.

http://developer.android.com/reference/android/graphics/Canvas.html#drawRGB%28int,%20int,%20int%29

but again: do RTFM first as there are other options you may want to
utilse (i.e. you may want to save as PNG instead of lossy JPEG) or
simply to know whene you will be trying to reinvent the wheel.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Canvas or Gesture??

2011-02-14 Thread Robin Talwar
Ok lemme refine the question.

How to use canvas to sensetize the touch event and then save the image
created by the user through touch and mail it as an attachment

On Mon, Feb 14, 2011 at 7:13 PM, Abhishek Talwar 
r.o.b.i.n.abhis...@gmail.com wrote:

 Hi guys
 I have to make an application in which the user can sign on the
 touchscreen and that signature
 of his gets saved in the device and then if he clicks on the mail
 button a mail is send with that sign image as an
 attachment.

 I spend some time doing this with gesture but now since i have googled
 much i think canvas can also do this.
 But my problem is that both of these are new to me so kindly suggest
 what should be my pick and how should i plan my quest over this
 particular problem.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Canvas or Gesture??

2011-02-14 Thread Marcin Orlowski
 How to use canvas to sensetize the touch event and then save the image
 created by the user through touch and mail it as an attachment

You do not use canvas to sense anything. Canvas is, as name indicates,
a way of drawing. And that's mainly it. If you want to react on user
gestures or touches, use GestureDetector process motionEvents your
listener get and paint them on your canvas.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Canvas or Gesture??

2011-02-14 Thread Robin Talwar
but i also need to save it and then convert the gesture to image and then
mail it as an attachment.
Is that all possible? can i convert a gesture into an image?

On Tue, Feb 15, 2011 at 2:06 AM, Marcin Orlowski
webnet.andr...@gmail.comwrote:

  How to use canvas to sensetize the touch event and then save the image
  created by the user through touch and mail it as an attachment

 You do not use canvas to sense anything. Canvas is, as name indicates,
 a way of drawing. And that's mainly it. If you want to react on user
 gestures or touches, use GestureDetector process motionEvents your
 listener get and paint them on your canvas.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en