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 7952347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:50:06+00:00 2026-06-04T02:50:06+00:00

I have created an app in which I have used SPenSdk libraries, My app

  • 0

I have created an app in which I have used SPenSdk libraries, My app is simple, What I do is on the start of the app I open a canvasView with a pen, eraser, undo and redo option.

I have two buttons, one save the canvas as an image in my SD card and another button is used to load the saved images.

Now my issue is, whenever I load the saved image and edit the saved images and again save the images, it is saved as new images instead of updating the saved images, why it happens?

I put my code here. Help me to solve this out, if possible with an example.

Code For java File

public class CanvasActivity extends Activity {
         
private CanvasView  m_CanvasView;
private SettingView m_SettingView;
private Button      m_PenButton, m_EraserButton, m_UndoButton, m_RedoButton, m_SaveButton;      
private int         mButtonTextNormalColor;

public static final String DEFAULT_APP_IMAGEDATA_DIRECTORY = "/mnt/sdcard/SmemoExample";

private File        m_Folder = null;
public static final String SAVED_FILE_EXTENSION = "png";
public static final String EXTRA_IMAGE_PATH = "path";
public static final String EXTRA_IMAGE_NAME = "filename";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    
    m_PenButton     = (Button) findViewById(R.id.pen_button);
    m_PenButton.setOnClickListener(mBtnClickListener);
    mButtonTextNormalColor = m_PenButton.getTextColors().getDefaultColor();
    
    m_EraserButton  = (Button) findViewById(R.id.erase_button);
    m_EraserButton.setOnClickListener(mBtnClickListener);
    
    m_UndoButton    = (Button) findViewById(R.id.undo_button);
    m_UndoButton.setOnClickListener(undoNredoBtnClickListener);
    m_UndoButton.setEnabled(false);
    
    m_RedoButton    = (Button) findViewById(R.id.redo_button);
    m_RedoButton.setOnClickListener(undoNredoBtnClickListener);       
    m_RedoButton.setEnabled(false);
    
    m_SaveButton    = (Button) findViewById(R.id.save_button);
    m_SaveButton.setOnClickListener(mBtnClickListener);
    
    m_CanvasView    = (CanvasView) findViewById(R.id.canvas_view);
    m_SettingView   = (SettingView) findViewById(R.id.setting_view);

    m_CanvasView.setSettingView(m_SettingView);
    m_CanvasView.setOnHistoryChangeListener(historyChangeListener);
    m_CanvasView.setInitializeFinishListener(mInitializeFinishListener);
    
    m_Folder        = new File(DEFAULT_APP_IMAGEDATA_DIRECTORY);
    
    String mFileName = getIntent().getStringExtra(EXTRA_IMAGE_NAME);        
    loadCanvas(mFileName);
}

private OnClickListener undoNredoBtnClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (v == m_UndoButton) {
            m_CanvasView.undo();
        } else if (v == m_RedoButton) {
            m_CanvasView.redo();
        }

        m_UndoButton.setEnabled(m_CanvasView.isUndoable());
        m_RedoButton.setEnabled(m_CanvasView.isRedoable());
    }
};

OnClickListener mBtnClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        if (v.getId() == m_PenButton.getId()) {
            m_CanvasView.changeModeTo(CanvasView.PEN_MODE);
            m_PenButton.setSelected(true);
            m_PenButton.setTextColor(Color.WHITE);
            m_EraserButton.setSelected(false);
            m_EraserButton.setTextColor(mButtonTextNormalColor);
            
            if (m_PenButton.isSelected()) {
                m_SettingView.showView(AbstractSettingView.PEN_SETTING_VIEW);

            }
        } else if (v.getId() == m_EraserButton.getId()) {
            m_CanvasView.changeModeTo(CanvasView.ERASER_MODE);

            m_EraserButton.setSelected(true);
            m_EraserButton.setTextColor(Color.WHITE);
            m_PenButton.setSelected(false);
            m_PenButton.setTextColor(mButtonTextNormalColor);
            
            if (m_EraserButton.isSelected()) {
                m_SettingView.showView(AbstractSettingView.ERASER_SETTING_VIEW);
            }
        } else if(v.getId() == m_SaveButton.getId()) {
            saveCanvas();
        }
    }
};

public boolean saveCanvas() {
    byte[] buffer = m_CanvasView.getData();

    if (buffer == null)
        return false;
    if (!(m_Folder.exists()))
        m_Folder.mkdirs();
    
    String savePath = m_Folder.getPath() + '/' + UtilitiesActivity.getUniqueFilename(m_Folder, "image", SAVED_FILE_EXTENSION);

    if (UtilitiesActivity.writeBytedata(savePath, buffer))
        return true;
    else
        return false;
}

public boolean loadCanvas(String fileName) {
    String loadPath = m_Folder.getPath() + '/' + fileName;
   
    byte[] buffer = UtilitiesActivity.readBytedata(loadPath);

    if (buffer == null)
        return false;

    m_CanvasView.setData(buffer);

    return true;
}

private CanvasView.OnHistoryChangeListener historyChangeListener = new CanvasView.OnHistoryChangeListener() {
    @Override
    public void onHistoryChanged(boolean bUndoable, boolean bRedoable) {
        m_UndoButton.setEnabled(bUndoable);
        m_RedoButton.setEnabled(bRedoable);
    }
};

CanvasView.InitializeFinishListener mInitializeFinishListener = new CanvasView.InitializeFinishListener() {

    @Override
    public void onFinish() {
        Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.canvas_bg);
        m_CanvasView.setBackgroundImage(bg);
        bg.recycle();
    }
};
}
  • 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-04T02:50:08+00:00Added an answer on June 4, 2026 at 2:50 am

    While you save an image, it takes a new name and save that. Old image wont be overwritten. So you can edit the save canvas function. The method shown below

    public boolean saveCanvas()
    {
    byte[] buffer = mCanvasView.getData();
    
    if(buffer == null)
            return false;
    
        String savePath = mFolder.getPath() + '/' + ExampleUtils.getUniqueFilename(mFolder, "image", SAVED_FILE_EXTENSION);
        Log.d(TAG, "Save Path = " + savePath);
    
        if(ExampleUtils.writeBytedata(savePath, buffer))
            return true;
        else 
            return false;       
    }
    

    function “getUniqueFilename” generates a new name.So if you update an image, just avoid the function

    ExampleUtils.getUniqueFilename(mFolder, "image", SAVED_FILE_EXTENSION);
    

    and save with old name. Then it will be overwritten.

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

Sidebar

Related Questions

I have created an app in which I have used achartengine to construct the
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app which allows users to buy non-consumable content. The retrieving-ids-payment-process
I have created an app that uses NSTimer, which gets triggered each second. My
I have created a library which reads the app.config file and gets the type
I have created an animated game app, In which I am using NSTimer to
I have managed to create a simple app which deletes (bypassing the recycle bin)
I have created a simple map app that shows the local garage sales in
I am totally new to WPF, I have created a simple WPF app that
I have created a provisional profile using 'Non Wild Card App ID'. Which does

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.