Solved

Camera Preview hang and image shown is distorted

Posted on 2011-09-02
1
1,004 Views
Last Modified: 2012-05-12
This is the code I used for taking a photo. But after it took a photo, the preview screen just hang there (see attached). The preview is distorted, but the file saved is perfectly fine.
preview screen hung
public void takePhoto() {    	
      Camera.PictureCallback myPictureCallback_jpeg = new Camera.PictureCallback() {
  	   public void onPictureTaken(byte[] imageData, Camera c) {     		   
					FileOutputStream outStream = null;
					try {
						outStream = new FileOutputStream(String.format(
								"/sdcard/%d.jpg", System.currentTimeMillis()));
						outStream.write(imageData);
						outStream.close();
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					} finally {
					}
					Preview.this.invalidate();
				}
			};
			mCamera.takePicture(null, null,myPictureCallback_jpeg);    
    }

Open in new window


0
Comment
Question by:humansg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
humansg earned 0 total points
ID: 36484301
After much research on the web, I think the problem does not lies with the coding.

Read these 2 websites.

http://stackoverflow.com/questions/3213741/camera-preview-on-android-strange-on-samsung-galaxy-s

http://stackoverflow.com/questions/2053440/camera-preview-on-android-strange-lines-on-1-5-version-of-sdk << Refering to this URL, if you set
parameters.setPreviewSize(h, w); //instead of w,h

Open in new window

it happens to work on Samsung handset. Tested on Galaxy S (2.1) and Galaxy S2 (2.3). But it simply crash on my HTC Desire.

It's just a strange behavior.

After upgrading the Galaxy S to 2.2, it should work. And remember to set your code back to the original
parameters.setPreviewSize(w, h);

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question