Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:52:32+00:00 2026-06-08T18:52:32+00:00

** THIS QUESTION WAS SUCCESSFULLY ANSWERED AND HAS BECOME A BLOG POST <- click

  • 0

**THIS QUESTION WAS SUCCESSFULLY ANSWERED AND HAS BECOME A BLOG POST <- click **

Hi I am a PHP developer I want to do a simple thing – I want to draw something drawn on a blank page on an Android Phone (with a finger with a largeish “emulated pen nib”) and store the bitmap as a jpeg on a server by http post.

Here is what I have so far but this is taken from a tutorial that is involved with writing sprites for a game.. And I cant’ adapt it

package com.my.example;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

public class DrawCapture extends Activity implements OnTouchListener{

    OurView v;
    Bitmap ball;
    float x,y;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.draw_capture);
        v = new OurView(this);
        v.setOnTouchListener(this);
        ball = BitmapFactory.decodeResource(getResources(), R.drawable.blueball);
        x = y = 0;
        setContentView(v);
    }

    @Override
    protected void onPause(){
        super.onPause();
        v.pause();
    }

    protected void onResume(){
        super.onResume();
        v.resume();
    }

    public class OurView extends SurfaceView implements Runnable{
        Thread t = null;
        SurfaceHolder holder;
        boolean isItOK = false;

        public OurView(Context context) {
            super(context);
            holder = getHolder();
        }

        public void run() {
            while (isItOK == true){

                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                //perform canvas drawing
                if (!holder.getSurface().isValid()){
                    continue;
                }
                Canvas c = holder.lockCanvas();
                onDraw(c);
                holder.unlockCanvasAndPost(c);
            }       
        }

        public void onDraw(Canvas c){
            c.drawARGB(255, 210, 210, 210);
            c.drawBitmap(ball, x - (ball.getWidth()/2), y - (ball.getHeight()/2), null);
        }

        public void pause(){
            isItOK = false;
            while(true){
                try{
                    t.join();
                } catch(InterruptedException e){
                    e.printStackTrace();
                }
                break;
            }
            t = null;
        }

        public void resume(){
            isItOK = true;
            t = new Thread(this);
            t.start();
        }
    }

    public boolean onTouch(View v, MotionEvent me){

        switch (me.getAction()){
            case MotionEvent.ACTION_DOWN : 
                x = me.getX();
                y = me.getY();              
                break;
            case MotionEvent.ACTION_UP : 
                x = me.getX();
                y = me.getY();              
                break;
            case MotionEvent.ACTION_MOVE : 
                x = me.getX();
                y = me.getY();              
                break;
        }
        return true;
    }
}

and here is the XML

<?xml version="1.0" encoding="utf-8"?>
<SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


</SurfaceView>

Can someone please help me? I feel I am close – I use the blueball as a pen nib I just want to “save” this and possibly I’ll need to have a button (or menu) on the XML page to do this ? I know it’s a bit of a beg but there are a lot of people online asking how to draw with your finger and save something to the “cloud” if people could respond with examples of the code (not references) I promise I will compile this into a proper tutorial piece of code for the eventual benefit of all. Including the PHP server side code that I already am really happy with.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:52:34+00:00Added an answer on June 8, 2026 at 6:52 pm

    You can try to use the Gesture Object proposed by Google, try to execute my following code :

    Activity1 xml :

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFFFF" >
    
            <android.gesture.GestureOverlayView
                android:id="@+id/gestures"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:fadeEnabled="false"
                android:fadeOffset="5000000000"
                android:gestureColor="#000000"
                android:gestureStrokeType="multiple"
                android:gestureStrokeWidth="1"
                android:uncertainGestureColor="#000000"
                android:layout_above="@+id/save_button" />
    
            <Button
                android:id="@id/save_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="20sp"
                android:paddingLeft="20sp"
                android:paddingRight="20sp"
                android:text="Save"
                android:textSize="22sp" />
    
        </RelativeLayout>
    

    Activity1 java :

     package com.testandroidproject;
    
    import java.io.ByteArrayOutputStream;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.gesture.GestureOverlayView;
    import android.graphics.Bitmap;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class Activity1 extends Activity {
    
        private Button button_save;
        private GestureOverlayView gesture;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.main);
    
            gesture = (GestureOverlayView) findViewById(R.id.gestures);
            button_save = (Button) findViewById(R.id.save_button);
    
            button_save.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    try {
                        Bitmap gestureImg = gesture.getGesture().toBitmap(100, 100,
                                8, Color.BLACK);
    
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        gestureImg.compress(Bitmap.CompressFormat.PNG, 100, bos);
                        byte[] bArray = bos.toByteArray();
    
                        Intent intent = new Intent(Activity1.this, Activity2.class);
    
                        intent.putExtra("draw", bArray);
                        startActivity(intent);
    
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(Activity1.this, "No draw on the string",
                                3000).show();
                    }
                }
            });
        }
    
    }
    

    Activity2 xml :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/image_saved"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" />
    
    </LinearLayout>
    

    Activity2 java :

    package com.testandroidproject;
    
    import java.io.ByteArrayInputStream;
    
    import android.app.Activity;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.widget.ImageView;
    
    
    public class Activity2 extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.display_image);
    
            ImageView image = (ImageView) findViewById(R.id.image_saved);
    
            ByteArrayInputStream imageStreamClient = new ByteArrayInputStream(
                    getIntent().getExtras().getByteArray("draw"));
            image.setImageBitmap(BitmapFactory.decodeStream(imageStreamClient));
        }
    
    }
    

    Hope you will find this helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up to #1644748 where I successfully answered my own question, but
Original question has been answered. Update addresses related question raised in comments. Original post:
This is tailing off my other question which was successfully answered: stackoverflow.com/questions/8597929/need-to-create-li-with-list-of-different-links-using-php-explode-method so now
Edit: I think this has been answered successfully, but I can't check 'til later.
This question is related to another question I wrote: Trouble using DOTNET from PHP.
I know this question has been asked before and I read all the answers
My apologies if this was answered in another question, I could not find an
Sorry if this has been answered already, but I think I actually lack the
This question has been asked many times before but it seems everyone else is
So earlier I asked this question: JQuery Login Redirect. Code Included The php file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.