我尝试使用表面视图捕获图像并将其保存在文件夹中。现在,当我在imageview中查看图像时,显示的图像会反转。如何在不反转的情况下看到图像。有任何建议请..........
这是代码的一部分..
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
rawCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Log.d("Log", "onPictureTaken - raw");
}
};
shutterCallback = new ShutterCallback()
{
public void onShutter() {
Log.i("Log", "onShutter'd");
}
};
jpegCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Asw/Raw Image");
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
name = s.toString() + ".jpg";
File output = new File(imagesFolder, name);
callname = "/sdcard/"Asw/RawImage/" + name;
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
ExifInterface exif = new ExifInterface(name);
int orientation = exif.getAttributeInt( ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
// Log.v(Common.TAG, "Exif orientation: " + orientation);
Log.d("Fragment", "EXIF info for file " +name+ ": " + rotate);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
Log.d("Fragment", "Could not get EXIF info for file " + name+ ": " + e);
}
finally
{}
Log.d("Log", "onPictureTaken - jpeg");
Bitmap bitmap = BitmapFactory.decodeFile(callname);
imageView.setImageBitmap(bitmap);//Displaying raw Image
logcat的
12-12 16:04:13.678: D/SurfaceView(1631): pckname = com.example.imaging
12-12 16:04:13.808: D/ViewRootImpl(1631): pckname = com.example.imaging
12-12 16:04:13.928: I/dalvikvm(1631): threadid=3: reacting to signal 3
12-12 16:04:13.928: I/dalvikvm(1631): Wrote stack traces to '/data/anr/traces.txt'
12-12 16:04:13.998: D/libEGL(1631): loaded /system/lib/egl/libEGL_mali.so
12-12 16:04:14.008: D/libEGL(1631): loaded /system/lib/egl/libGLESv1_CM_mali.so
12-12 16:04:14.008: D/libEGL(1631): loaded /system/lib/egl/libGLESv2_mali.so
12-12 16:04:14.038: D/OpenGLRenderer(1631): Enabling debug mode 0
12-12 16:04:23.048: I/Log(1631): onShutter'd
12-12 16:04:23.048: D/Log(1631): onPictureTaken - raw
12-12 16:04:23.118: E/JHEAD(1631): can't open '/sdcard/Asw/Raw Image/12-12-13 04-04-23.jpg'
12-12 16:04:23.148: D/Log(1631): onPictureTaken - jpeg
12-12 16:04:23.188: D/dalvikvm(1631): GC_FOR_ALLOC freed 122K, 4% free 5912K/6151K, paused 39ms
12-12 16:04:23.208: I/dalvikvm-heap(1631): Grow heap (frag case) to 6.453MB for 614416-byte allocation
12-12 16:04:23.258: D/dalvikvm(1631): GC_CONCURRENT freed 6K, 5% free 6505K/6791K, paused 2ms+2ms
12-12 16:04:23.348: D/dalvikvm(1631): GC_FOR_ALLOC freed 32K, 5% free 6474K/6791K, paused 66ms
12-12 16:04:23.348: I/dalvikvm-heap(1631): Grow heap (frag case) to 7.587MB for 1228816-byte allocation
12-12 16:04:23.418: D/dalvikvm(1631): GC_CONCURRENT freed <1K, 5% free 7674K/8007K, paused 3ms+2ms
12-12 16:04:29.368: D/dalvikvm(1631): GC_FOR_ALLOC freed 6K, 4% free 7714K/8007K, paused 44ms
12-12 16:04:29.368: I/dalvikvm-heap(1631): Grow heap (frag case) to 8.212MB for 614416-byte allocation
12-12 16:04:29.438: D/dalvikvm(1631): GC_CONCURRENT freed <1K, 4% free 8314K/8647K, paused 2ms+2ms
12-12 16:04:29.468: D/ViewRootImpl(1631): pckname = com.example.imaging
12-12 16:04:31.358: D/OpenGLRenderer(1631): Flushing caches (mode 0)
12-12 16:04:31.428: W/IInputConnectionWrapper(1631): showStatusIcon on inactive InputConnection
12-12 16:04:31.908: D/OpenGLRenderer(1631): Flushing caches (mode 1)
答案 0 :(得分:0)
试试这段代码,希望对你有帮助。
int rotate = 0;
try {
getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Log.v("***TAG***", "Exif orientation: " + orientation);
} catch (Exception e) {
e.printStackTrace();
}