图像反转:Android
Posted
技术标签:
【中文标题】图像反转:Android【英文标题】:Image getting reversed : Android 【发布时间】:2013-12-30 14:30:18 【问题描述】:我尝试使用表面视图捕获图像并将其保存在文件夹中。现在,当我在 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
日志猫
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)
【问题讨论】:
见***.com/a/20480741/2556111 【参考方案1】:试试这个代码,希望对你有帮助。
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();
【讨论】:
我已经编辑了代码......我添加了这个代码......bt它不起作用......你能验证代码吗 在onPictureTaken方法中,捕获图像后保存图像 Common.TAG 只是一个字符串 当我添加这一行 Log.v(Common.TAG, "Exiforientation:" +orientation);共同未解决.... 我告诉过你它是一个字符串,你可以在这里放任何字符串,就像我更新我的解决方案一样。以上是关于图像反转:Android的主要内容,如果未能解决你的问题,请参考以下文章