How can I access pixel colors of camera pictures

All your problems with Audio, Video and Images.

How can I access pixel colors of camera pictures

Postby jjoe64 » Tue Dec 29, 2009 7:09 pm

hello.

When I capture a picture from camera I get the jpeg data:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onPictureTaken(byte[] data, Camera camera)
  3.  
  4.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


How can I access pixel colors of camera pictures?

Is it possible to load the data array in a Bitmap-Object, because this class provides methods to access pixel (e.g. getPixel())? Or any other ideas?

Thanks.
jjoe64
Freshman
Freshman
 
Posts: 4
Joined: Tue Dec 29, 2009 6:04 pm

Top

Postby nhenze » Mon Jan 11, 2010 5:33 pm

I use the following code snippet to extract the pixel data from taken photos. I scale the bitmap to use less memory. Since I don't know the default image format I also convert the bitmap to RGB565. Afterwards, the photo's pixel are in the ByteBuffer buffer. I alter this buffer and produce an OpenGL texture but you could also do other things if you like.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onPictureTaken(byte[] jpeg, Camera camera) {
  3.  
  4.         Bitmap bitmap=BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
  5.  
  6.         Bitmap scaledBitmap=Bitmap.createScaledBitmap(bitmap, 512, 384, false);
  7.  
  8.         scaledBitmap=scaledBitmap.copy(Bitmap.Config.RGB_565, false);
  9.  
  10.         Buffer buffer=ByteBuffer.allocateDirect(scaledBitmap.getWidth()*scaledBitmap.getHeight()*2);           
  11.  
  12.         scaledBitmap.copyPixelsToBuffer(buffer);
  13.  
  14. }
  15.  
  16.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
nhenze
Freshman
Freshman
 
Posts: 9
Joined: Thu Dec 10, 2009 10:34 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 15 guests