0

I am trying to learn how to use ndk and renderscript. This is what i tried so far. I am using renderscript to convert nv21 frame to rgb. After that, i am getting the pixels from the rgb and sending the pixels to the ndk script to convert to grayscale. Then i created a bitmap from the grayscale pixels and i am rendering the bitmap to the imageview. Things seem to be working fine. However, I am facing an issue. When the preview is rendered in the imageview, the bitmap appears to be rotated. What could i be doing wrong ?

  • You can check the exif data of the image, see [this](https://stackoverflow.com/questions/20478765/how-to-get-the-correct-orientation-of-the-image-selected-from-the-default-image) – Faruk Yazici Aug 17 '18 at 09:01
  • You see when you take photo in portrait mode right? The problem is not about your bitmap conversion. Problem about orientation and saving since most phones use landscape orientation as default. You can check out this question for your problem. https://stackoverflow.com/questions/16128608/camera-preview-is-in-portrait-mode-but-image-captured-is-rotated/31556098 – Alperen Kantarcı Aug 17 '18 at 09:06
  • You probably do nothing wrong. But if the image gets rotated in landscape and portrait on all devices you could simply rotate the bitmap or tell the ImageView to display the bitmap rotated. – greenapps Aug 17 '18 at 09:10
  • @greenapps:- I tried rotating the imageview but then the grayscale effect disappears. – anastacia das Aug 17 '18 at 09:17
  • Strange. But then rotate the bitmap. Use a Matrix. – greenapps Aug 17 '18 at 09:18
  • `You can check the exif data of the image` @Faruk Yazıcı ImageFormat.NV21 includes an exif header? Dont think so. – greenapps Aug 17 '18 at 09:21

1 Answers1

0

The NV21 frame received from the camera on most phones is always in landscape (see CameraInfo.orientation.

I tried rotating the imageview but then the grayscale effect disappears

Please show your code, there is some easy typo probably

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307