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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:01:01+00:00 2026-05-31T03:01:01+00:00

I’m trying the openCV sample on Android. When I’m trying to save a bmp

  • 0

I’m trying the openCV sample on Android. When I’m trying to save a bmp file to my SDcard every thread using following code:

String filePath = "/sdcard"; // some times it may be only /sdcard not /mnt/sdcard
        filePath += "newFileName.jpg";
        try {
             bmp.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File(filePath)));
        } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
        e.printStackTrace();
        Log.i(TAG, "IOException Occurred!!!");   
        }

The log always shows up “IOException Occurred” and no file have been saved on SDcard.

The full class code is below

public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable {
private static final String TAG = "Sample::SurfaceView";

private SurfaceHolder       mHolder;
private VideoCapture        mCamera;
private FpsMeter            mFps;

public SampleCvViewBase(Context context) {
    super(context);
    mHolder = getHolder();
    mHolder.addCallback(this);
    mFps = new FpsMeter();
    Log.i(TAG, "Instantiated new " + this.getClass());
}

public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {//called immediately after the structural change of surface
    Log.i(TAG, "surfaceCreated");
    synchronized (this) {
        if (mCamera != null && mCamera.isOpened()) {
            Log.i(TAG, "before mCamera.getSupportedPreviewSizes()");
            List<Size> sizes = mCamera.getSupportedPreviewSizes();
            Log.i(TAG, "after mCamera.getSupportedPreviewSizes()");
            int mFrameWidth = width;
            int mFrameHeight = height;

            // selecting optimal camera preview size
            {
                double minDiff = Double.MAX_VALUE;
                for (Size size : sizes) {
                    if (Math.abs(size.height - height) < minDiff) {
                        mFrameWidth = (int) size.width;
                        mFrameHeight = (int) size.height;
                        minDiff = Math.abs(size.height - height);
                    }
                }
            }

            mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
            mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
        }
    }
}

public void surfaceCreated(SurfaceHolder holder) {
    Log.i(TAG, "surfaceCreated");
    mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
    if (mCamera.isOpened()) {
        (new Thread(this)).start();     //new thread
    } else {
        mCamera.release();
        mCamera = null;
        Log.e(TAG, "Failed to open native camera");
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    Log.i(TAG, "surfaceDestroyed");
    if (mCamera != null) {
        synchronized (this) {
            mCamera.release();                      
            mCamera = null;
        }
    }
}

protected abstract Bitmap processFrame(VideoCapture capture) throws IOException;

public void run() {
    Log.i(TAG, "Starting processing thread");       //send out log notice
    mFps.init();                                //instance of Fps meter    

    while (true) {
        Bitmap bmp = null;

        synchronized (this) {
            if (mCamera == null)                    //instance of video capture
                break;

            if (!mCamera.grab()) {
                Log.e(TAG, "mCamera.grab() failed");
                break;
            }

            try {
                bmp = processFrame(mCamera);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            mFps.measure();
        }

        if (bmp != null) {
            Canvas canvas = mHolder.lockCanvas();
            if (canvas != null) {
                canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2, null);
                mFps.draw(canvas, (canvas.getWidth() - bmp.getWidth()) / 2, 0);
                mHolder.unlockCanvasAndPost(canvas);
            }
            String filePath = "/sdcard"; // some times it may be only /sdcard not /mnt/sdcard
            filePath += "newFileName.jpg";
            try {
                 bmp.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File(filePath)));
            } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
            e.printStackTrace();
            Log.i(TAG, "IOExcpetion Occurred!!!");   
            }
        }

Here is what I’ve got in DDMS:

03-07 08:58:11.639: W/TextLayoutCache(986): computeValuesWithHarfbuzz -- need to force to single run
03-07 08:58:11.709: W/System.err(986): java.io.FileNotFoundException: /sdcardnewFileName.jpg: open failed: EROFS (Read-only file system)
03-07 08:58:11.769: W/System.err(986):  at libcore.io.IoBridge.open(IoBridge.java:406)
03-07 08:58:11.769: W/System.err(986):  at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
03-07 08:58:11.809: W/System.err(986):  at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
03-07 08:58:11.829: W/System.err(986):  at org.opencv.samples.fd.SampleCvViewBase.run(SampleCvViewBase.java:125)
03-07 08:58:11.829: W/System.err(986):  at org.opencv.samples.fd.FdView.run(FdView.java:107)
03-07 08:58:11.829: W/System.err(986):  at java.lang.Thread.run(Thread.java:856)
03-07 08:58:11.829: W/System.err(986): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
03-07 08:58:11.859: W/System.err(986):  at libcore.io.Posix.open(Native Method)
03-07 08:58:11.859: W/System.err(986):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:98)
03-07 08:58:11.889: W/System.err(986):  at libcore.io.IoBridge.open(IoBridge.java:390)
03-07 08:58:11.889: W/System.err(986):  ... 5 more

03-07 08:58:11.919: I/Sample::SurfaceView(986): IOExcpetion Occurred!!!

03-07 08:58:12.489: D/dalvikvm(986): GC_FOR_ALLOC freed 1209K, 14% free 9902K/11399K, paused 29ms
03-07 08:58:12.489: I/dalvikvm-heap(986): Grow heap (frag case) to 10.925MB for 1228816-byte allocation
03-07 08:58:12.619: D/dalvikvm(986): GC_CONCURRENT freed <1K, 3% free 11102K/11399K, paused 3ms+45ms

I’m trying to save one bmp image as soon as the detection has completed once. Can anyone help me?Thank you

  • 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-05-31T03:01:02+00:00Added an answer on May 31, 2026 at 3:01 am

    You are trying to write into the filesystem root because you missed a forward slash in your file path: You use /sdcardnewFileName.jpg instead of /sdcard/newFileName.jpg.
    But you got no permission to write there, so you get an exception.

    Also: Please don’t hardcode the path to the SD-card like this at all. Instead use Environment.getExternalStorageDirectory(). Some devices mount the card on a different path or have flash memory instead. This method always returns the correct path. If you don’t do this, you will run into problems when using your app across multiple devices.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.