Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Camera Preview hang and image shown is distorted

Posted on 2011-09-02
1
Medium Priority
?
1,029 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.
If you use the Google Now Launcher, as an aftermarket add on, have a Samsung Note 5 and are worried about power consumption be wary of using the ultra power saving mode.  Here is what happened to me when I made the mistake of trying this out...
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…

926 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