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
Solved

Camera Preview hang and image shown is distorted

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

First off, some of you reading this are already thinking there is an error in the title. It really should be Kindle Fire versus OTHER Android tablets. That's because the Amazon Kindle Fire IS an Android tablet. Well, it is and it's not. It's running…
Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
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…

828 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