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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:57:03+00:00 2026-06-01T02:57:03+00:00

I am trying to get a camera preview with a color effect applied to

  • 0

I am trying to get a camera preview with a color effect applied to it, such as for example the NEGATIVE effect. There are no errors, and the preview is visible without problems, but independent of the ColorEffect I set – the camera preview remains unchanged. I tested if the effects I am trying to use are available to my phone by running params.getSupportedColorEffects() (also these effects also work in the built in photo app).

I have no idea what is wrong with the code – I am posting it below. Perhaps someone here has an idea what could make this work? Thanks in advance.

public class CustomCameraView extends SurfaceView{

Camera mCamera;
SurfaceHolder mHolder;

public CustomCameraView(Context context){
    super(context);
    mHolder = this.getHolder();
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mHolder.addCallback(mSurfaceHolderListener);
}

SurfaceHolder.Callback mSurfaceHolderListener = new SurfaceHolder.Callback() {
    public void surfaceCreated(SurfaceHolder holder) {
        mCamera=Camera.open();
        try {
            mCamera.setPreviewDisplay(mHolder);
        }
        catch (Exception e){ }
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height)
    {
        Camera.Parameters params = mCamera.getParameters();
        params.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
        mCamera.setParameters(params);
        mCamera.startPreview();
    }

    public void surfaceDestroyed(SurfaceHolder arg0)
    {
        mCamera.stopPreview();
        mCamera.release();   
    }
};
}

After some testing it turned out the problem could be related to the HTC Desire I was testing on (or maybe its OS version). The code works correctly on some other Samsung phones. I haven’t figured out what could be the problem on the HTC.


UPDATE:
I have managed to get the effects working, but truly by accident, and I still don’t understand why. But I will give the answer here – perhaps someone will find it useful, or maybe will be able to explain why it happens this way:

I added the following line to the surfaceChanged method because I was trying to decrease the size of the preview:

previewHolder.setFixedSize(width, height-1); 

This had the result of making the selected effect visible.

When I changed this line to:

previewHolder.setFixedSize(width, height); 

the effect was not visible any more once again. So odd…. it works for set height being anything less than the received height parameter.

  • 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-01T02:57:05+00:00Added an answer on June 1, 2026 at 2:57 am

    I have been struggling with this as well. I found out that the HTC Desire its camera needs a strange order of executing the setParameters, setPreviewDisplay and startPreview for the color effect to work. The order is:

    Camera.Parameters parameters = camera.getParameters();
    
    //set the parameters
    
    camera.setParameters(parameters);
    camera.startPreview();
    camera.setParameters(parameters);
    camera.setPreviewDisplay(surfaceHolder);
    

    Calling startPreview before setPreviewDisplay is documented in the Android SDK as a way of initializing the camera and the surfaceView in parallel.

    Regarding your update about getting the effects to work by accident, the same happend to me! I assume for the same reason, some of my code got called twice in quick succesion (in my case due to a changing database object). This caused the method to (re)set the parameters and (re)start the preview to be called twice producing the desired result. After realising this and some more experimenting the above order seemed to work on both my HTC Desire and Acer Iconia A500 and I was quite happy with it.

    However I have just received a comment for my application saying it produces corrupted images on the HTC Desire HD so I would recommend not using this order of camera initialization as a default but rather as a fix for the HTC Desire.

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

Sidebar

Related Questions

I am trying to create bitmap class using bitmapfactory. I get camera preview image
I'm new at java and OpenGL. I'm trying to get a camera preview screen
I've got a Sony network camera (SNC-RZ25N) that I am trying desperately to get
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get a JSON output to work with jqGrid 'userdata' option. The example
I am trying to develop a custom widget for camera preview. I would like
I'm trying to capture an image from the camera preview and convert it to
I have created an application where i have a camera preview. I am trying
I am trying to get camera feeds in Windows 8 metro style app so
I'm trying to draw something on the camera preview. But when the program call

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.