android


Android CameraSource works differently for multiple devices and doesn't rotate image


I have two android devices. CameraSource works differently for them.
For one device the orientation of photo is correct without rotate after saving. But for another device saved the photo with wrong orientation.
I've created CameraSource:
source = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(cameraId)
.setRequestedFps(30.0f)
.setAutoFocusEnabled(true)
.build();
I've created button with action:
source.takePicture(null, new CameraSource.PictureCallback() {
#Override
public void onPictureTaken(byte[] bytes) {
File folder = PhotoUtils.getGalleryFolder();
writeFileIntoDevice(bytes, folder.getAbsolutePath());
}
});
private String writeFileIntoDevice(byte[] data, String path) {
Bitmap orignalImage = BitmapFactory.decodeByteArray(data, 0, data.length);
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_hhmmss");
String fileName = formatter.format(new Date());
File file = new File(path, fileName + ".jpg");
try (FileOutputStream stream = new FileOutputStream(file)) {
orignalImage.compress(Bitmap.CompressFormat.JPEG, 80, stream);
Log.i(PhotoCreator.class.getName(), "photo was saved to " + path);
} catch (Exception e) {
Log.e(PhotoCreator.class.getName(), "can't save photo", e);
}
return file.getAbsolutePath();
}
Orientation of photos is different on the devices and I tried to rotate bitmap after save but without success.
I tried this: Controlling the camera to take pictures in portrait doesn't rotate the final images
And this: Android camera resulted image should be rotated after the capture?
How to rotate image correctly for all devices?
With two different devices, I am getting two different results. I am just starting the camera. With one device, I get the video preview properly, with another device, I get the video preview which is rotated by 90 degrees clockwise. My app is in landscape on an Android tablet.
I did not find any solution to fix this camera rotation issue.
cameraView = (SurfaceView)findViewById(R.id.cameraView);
barcodeDetector = new BarcodeDetector.Builder(this)
.setBarcodeFormats(Barcode.QR_CODE)
.build();
cameraSource = new CameraSource
.Builder(this, barcodeDetector)
.setAutoFocusEnabled(true)
.setRequestedFps(60)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.build();
cameraSource.start(holder);

Related Links

Android: Using ListView ArrayAdapter/ArrayList
Accelerometer Jump/Walk/Run Gesture, Which method to use
Listview Holder positions shuffled
trying to allow certain contacts to ring even the phone is in silent mode
Changing the icon in actionbar
Convenient way to find out whether onReceive on BroadcastReceiver was called while the application was running?
retaining image orientation after compression
Scanning radio syslogs in Android
Android Gingerbread NOT Catching Heap out of extermal memory (i.e. NOT Dalvik Heap Memory)?
Testing with a Virgin Mobile Chaser phone
What is the difference between setDisplayHomeAsUpEnabled and setHomeButtonEnabled?
Listview with CursorAdapter
OnLocationChanged vs. AddProximityAlert
iterating through Cursor in CursorAdapter.bindView
How to add application in google play for private channel
How to open an activity which only occupied two-thirds screen? And the rest of the screen display the parent activity

Categories

HOME
microsoftgraph
prism
eslint
apache-flink
pagination
phpmyadmin
zend-framework
swt
rds
joomla3.0
teechart
categorical-data
appcelerator-studio
project-intu
libc
selenium-ide
flatpak
symbol
event-sourcing
glyphicons
powershell-v5.0
forgot-password
solrcloud
replication
simpleitk
href
gulp-watch
tosca
pic32
apktool
finagle
panoramas
mustache
sammy.js
reverse
apiary.io
raft
sim-toolkit
openproject
wurfl
apache-stanbol
ogc
dcmtk
tcc
android-checkbox
android-exoplayer
fwrite
vugen
manova
zenhub
payara-micro
arq
modelsim
arules
rackspace-cloud
gpg-signature
d3-force-directed
universal-analytics
visual-studio-2008-sp1
async.js
dotnetnuke-7
resourcemanager
beamer
respondcms
ellucian-scribe
aspen
realsense
themoviedb-api
microsoft-reporting
cwrsync
actionfilterattribute
cosine-similarity
viewer
browserify-shim
pseudo-class
ray
decoupling
hibernate-entitymanager
cnf
facebook-timeline
video-codecs
superscrollorama
monotouch.dialog
boost-msm
dajaxice
adobe-media-server
subgraph
httponly
agility.js
luabind
pinch
exponentiation
inline-formset
django-paypal
office-2007
sifr
cfwindow
entitykey
pbcopy
blind

Resources

Encrypt Message