Solved

Camera Preview hang and image shown is distorted

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.
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…

813 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

15 Experts available now in Live!

Get 1:1 Help Now