Solved

Camera Preview hang and image shown is distorted

Posted on 2011-09-02
1
983 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Android SDK is used for creating an android software application. It includes document and tools which are necessary to develop applications with java. In fact Android SDK is harder than other software infrastructure, because there is a virtual devi…
Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now