How to convert byte [] EncodedImage rgb565 or bitmap data

Hi all I am playing a video and I want to get snapshot of video as

Byte [] byteArr = videoControl.getSnapshot ("encoding = rgb565");

I try to get the Bitmap as

image = EncodedImage.createEncodedImage (byteArr, 0, byteArr.length);

image bitmap = image.getBitmap ();

but she throws an Exception as IllegalArgumentException.

I get a table of double length than screenWidth * ScreenHeight, perhaps because of the rgb565

How can I convert a byte [] bitmap.

I solve the problem to get the bitmap by building as

image bitmap = new Bitmap (Bitmap.ROWWISE_16BIT_COLOR, Graphics.getScreenWidth (), Graphics.getScreenHeight (), byteArr);

Tags: BlackBerry Developers

Similar Questions

  • [Oracle 8i] How to convert a string (timestamp) in a date?

    I find it difficult to know how to convert a string to a date time stamp (or possibly several).

    The timestamp is 20 positions, character (NOT NULL, CHAR (20))
    in the format: YYYYMMDDHHMMSSUUUUUU
    where Y = year, M = month, D = day, M = Minutes, S = seconds and U = microseconds

    The reason why I want to convert it is so that I can compare a timestamp to each other (that is, I want to be able to find the MIN (timestamp), MAX (timestamp) and make comparisons of inequality).

    Is this possible?

    Thanks in advance for the help on this!

    Hello

    As Damorgan said, if all you want to do is find which is the earlier or later, then you can just compare the strings: they are in a format where it works.

    If you need to do other things, such as compare to today date or see the difference between two of your lines of days, you will need to convert it to date. (He has no reason to convert them to numbers).

    A new TIMESTAMP data type, which manages the fractions of a second, was introduced in Oracle 9.
    Since you use Oracle 8 (depending on your subject line), or it must be
    (1) ignores the microseconds, or
    (2) use a separate column for microseconds.

    Whatever it is, use TO_DATE to convert the first 14 characters in DATE:

    TO_DATE ( SUBSTR (txt, 1, 14)
            , 'YYYYMMDDHH24MISS'
            )
    

    where txt is your column of type CHAR.
    To convert microseconds to a number (between 0 and 999999):

    TO_NUMBER (SUBSTR (txt, 15))
    
  • How to convert the analog voltage input form data to True and false (0 = fasle 0: 1-10 = true)

    I want to use for LED or photo

    10 V to ai0 reciece ex to see the LED or photo on front panel

    Help me please

    As part of the comparison, it should look like this.

    Freelance LV cited above, you must provide additional information to get an apt solution

  • How to convert java.sql.ResultSet to intradoc.data.DataResultSet

    I used a MS jdbc driver to perform a query and got a java.sql.ResultSet.
    Now when I try this

    DRS DataResultSet = new DataResultSet();
    ResultSet rs = stmt.executeQuery (sqlString);
    Drs.Copy ((intradoc. (Data.ResultSet) rs);

    I get an error "ClassCastException.
    But they compile even without the cast.

    I also tried this:

    {while (RS. Next())}
    trace ("CPC" + rs.getString (1));
    String s = rs.getString (1);
    Vector v = new Vector < String > < String > ();
    v.Add (s);
    drs.addRow (v);
    }

    and I get an error
    Caused by: java.lang.Error:! syFailedAppendRow

    Is there a way to do it (or something)? Y at - it the javadoc for intradoc.data.DataResultSet?

    I'm using eclipse and JRE 1.5
    And injectors scanner stellant 10gr 4

    Thank you

    Published by: kgough on March 2, 2011 06:36

    If this does not work, you can always try something like this

    public static DataResultSet toDataResultSet(
         final java.sql.ResultSet p_resultset,
         final boolean p_closeAfterCopy
    ) throws SQLException {
    
         final ResultSetMetaData rsmd = p_resultset.getMetaData();
         final int columnCount = rsmd.getColumnCount();
    
         // get headings
         final String[] columnNames = new String[ columnCount ];
         final int[] columnTypes = new int[ columnCount ];
         for ( int i = 0 ; i < columnCount ; i++ ) {
              columnNames[ i ] = rsmd.getColumnName( i + 1 );
              columnTypes[ i ] = rsmd.getColumnType( i + 1 );
         }
    
         final DataResultSet dataResultSet = new DataResultSet( columnNames );
    
         while ( p_resultset.next() ) {
    
              Vector row = new Vector();
              for ( int i = 0 ; i < columnCount ; i++ ) {
    
                   final int fieldType = columnTypes[ i ];
    
                   //if ( fieldType != Types.CHAR || fieldType != Types.VARCHAR ) {
                   //     // if you want stuff other than string, do smart stuff here
                   //}
                   row.add( p_resultset.getString( i + 1 ) );
    
              }
              dataResultSet.addRow( row );
    
         }
    
         if ( p_closeAfterCopy ) {
              p_resultset.close();
         }
    
         return dataResultSet;
    
    }
    
  • How to convert the object Bitmap to byteArray.

    Hi all

    I had a problem in the conversion of the bitmap object to. BMP file.

    (Real need: capture the screen shot and convert that turned to the screen.) BMP image and I have to keep this image in the SCARD

    I shouldn't use any PNGEncodedImage or JPEGEncodedImage )

    I capture the screen shot using the

    Bitmap BM = new Bitmap (width, height);

    Display.screenshot (WB);

    to get the data from [] bytes of this bitmap object that I use

    Byte [] _bytes = getBytesFromBitmap (bitmap);

    public byte [] getBytesFromBitmap (Bitmap bmp) {}
    try {}
    int height = bmp.getHeight ();
    int width = bmp.getWidth ();
    int [] rgbdata = new int [width * height];
    ByteArrayOutputStream Bos = new ByteArrayOutputStream();
    DataOutputStream back = new DataOutputStream (bos);
    Graphics g = new Graphics (bmp);
    bmp.getARGB(rgbdata,0,width,0,0,width,height);
    for (int i = 0; i)< rgbdata.length="" ;="" i++)="">
    If (rgbdata [i]! = - 1) {}
    dos.writeInt (i);
    back. Flush();
    //l++;
    }
    }
    Bos.Flush ();
    Return bos.toByteArray ();
    }
    catch (Exception ex) {}
    Dialog.Alert ("getBytesFromBitmap:" + ex.toString ());
    Returns a null value.
    }

    If I use this byte array in the Sub statement I get the "IllegalArgumentException".

    BMPEncodedImage.createEncodedImage (_bytes, 0, _bytes .length);

    all can help me how I can get the byte [] data from the bitmap object?

    import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.io.IOException;
    
    import javax.microedition.lcdui.Image;
    
    /** * @author Samuel Halliday */public final class BMPGenerator {
    
        /**     * @param image     * @return     * @throws IOException     * @see {@link #encodeBMP(int[], int, int)}     */    public static byte[] encodeBMP(Image image) throws IOException {        int width = image.getWidth();        int height = image.getHeight();        int[] rgb = new int[height * width];        image.getRGB(rgb, 0, width, 0, 0, width, height);        return encodeBMP(rgb, width, height);    }
    
        /**     * A self-contained BMP generator, which takes a byte array (without any unusual     * offsets) extracted from an {@link Image}. The target platform is J2ME. You may     * wish to use the convenience method {@link #encodeBMP(Image)} instead of this.     * 

    * A BMP file consists of 4 parts:- *

      *
    • header
    • *
    • information header
    • *
    • optional palette
    • *
    • image data
    • *
    * At this time only 24 bit uncompressed BMPs with Windows V3 headers can be created. * Future releases may become much more space-efficient, but will most likely be * ditched in favour of a PNG generator. * * @param rgb * @param width * @param height * @return * @throws IOException * @see http://en.wikipedia.org/wiki/Windows_bitmap */ public static byte[] encodeBMP(int[] rgb, int width, int height) throws IOException { int pad = (4 - (width % 4)) % 4; // the size of the BMP file in bytes int size = 14 + 40 + height * (pad + width * 3); ByteArrayOutputStream bytes = new ByteArrayOutputStream(size); DataOutputStream stream = new DataOutputStream(bytes); // HEADER // the magic number used to identify the BMP file: 0x42 0x4D stream.writeByte(0x42); stream.writeByte(0x4D); stream.writeInt(swapEndian(size)); // reserved stream.writeInt(0); // the offset, i.e. starting address of the bitmap data stream.writeInt(swapEndian(14 + 40)); // INFORMATION HEADER (Windows V3 header) // the size of this header (40 bytes) stream.writeInt(swapEndian(40)); // the bitmap width in pixels (signed integer). stream.writeInt(swapEndian(width)); // the bitmap height in pixels (signed integer). stream.writeInt(swapEndian(height)); // the number of colour planes being used. Must be set to 1. stream.writeShort(swapEndian((short) 1)); // the number of bits per pixel, which is the colour depth of the image. stream.writeShort(swapEndian((short) 24)); // the compression method being used. stream.writeInt(0); // image size. The size of the raw bitmap data. 0 is valid for uncompressed. stream.writeInt(0); // the horizontal resolution of the image. (pixel per meter, signed integer) stream.writeInt(0); // the vertical resolution of the image. (pixel per meter, signed integer) stream.writeInt(0); // the number of colours in the colour palette, or 0 to default to 2n. stream.writeInt(0); // the number of important colours used, or 0 when every colour is important; // generally ignored. stream.writeInt(0); // PALETTE // none for 24 bit depth // IMAGE DATA // starting in the bottom left, working right and then up // a series of 3 bytes per pixel in the order B G R. for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { int val = rgb[i + width * j]; stream.writeByte(val & 0x000000FF); stream.writeByte((val >>> 8 ) & 0x000000FF); stream.writeByte((val >>> 16) & 0x000000FF); } // number of bytes in each row must be padded to multiple of 4 for (int i = 0; i < pad; i++) { stream.writeByte(0); } } byte[] out = bytes.toByteArray(); bytes.close(); // quick consistency check if (out.length != size) throw new RuntimeException("bad math"); return out; } /** * Swap the Endian-ness of a 32 bit integer. * * @param value * @return */ private static int swapEndian(int value) { int b1 = value & 0xff; int b2 = (value >> 8 ) & 0xff; int b3 = (value >> 16) & 0xff; int b4 = (value >> 24) & 0xff; return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0; } /** * Swap the Endian-ness of a 16 bit integer. * * @param value * @return */ private static short swapEndian(short value) { int b1 = value & 0xff; int b2 = (value >> 8 ) & 0xff; return (short) (b1 << 8 | b2 << 0); } } Found form the Link mentioned below:
    http://javablog.co.uk/2007/12/26/j2me-bitmap-encoder/
  • Convert byte [] to bitmap

    How convert byte [] bitmap and convert bitmap to byte [] image and when to get the image of the server back to a string how to parse this string for byte [] exmple in android it parse like that

    byte[] logoImg = Base64.decode(jLogo.getString(i), 0);
    

    Thanks in advance

    Hello

    You can use the method createBitmapFromBytes of the Bitmap class to convert an array of bytes to a Bitmap image. If you know that the image will be in PNG format you can even use createBitmapFromPNG

    Specification of the API:

    http://www.BlackBerry.com/developers/docs/7.0.0api/NET/rim/device/API/system/bitmap.html#createBitma...

    http://www.BlackBerry.com/developers/docs/7.0.0api/NET/rim/device/API/system/bitmap.html#createBitma...

  • How to convert the Bitmap Image in BlackBerry

    Hello

    In my application, I get the picture from the server. Now, I want to convert this Bitmap Image to display on the screen. For this I use below codes. But it doesn't give me the same image does not mean with the clarity and the exact size. He's smaller than the picture.

    I used the codes below:

    private Bitmap getBitmapFromImg(Image img) {
            Bitmap bmp = null;
            try {
                Logger.out(TAG, "It is inside the the image conversion        " +img);
                Image image = Image.createImage(img);
                byte[] data = BMPGenerator.encodeBMP(image);
                Logger.out(TAG, "It is inside the the image conversion---333333333"+data);
                bmp = Bitmap.createBitmapFromBytes(data, 0, data.length, 1);
                } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return bmp;
            // TODO Auto-generated method stub
        }
    

    Here is the BMPGenerator class:

    public final class BMPGenerator {
    
            /**
             * @param image
             * @return
             * @throws IOException
             * @see {@link #encodeBMP(int[], int, int)}
             */
            public static byte[] encodeBMP(Image image) throws IOException {
                    int width = image.getWidth();
                    int height = image.getHeight();
                    int[] rgb = new int[height * width];
                    image.getRGB(rgb, 0, width, 0, 0, width, height);
                    return encodeBMP(rgb, width, height);
            }
    
            /**
             * A self-contained BMP generator, which takes a byte array (without any unusual
             * offsets) extracted from an {@link Image}. The target platform is J2ME. You may
             * wish to use the convenience method {@link #encodeBMP(Image)} instead of this.
             * 

    * A BMP file consists of 4 parts:- *

      *
    • header
    • *
    • information header
    • *
    • optional palette
    • *
    • image data
    • *
    * At this time only 24 bit uncompressed BMPs with Windows V3 headers can be created. * Future releases may become much more space-efficient, but will most likely be * ditched in favour of a PNG generator. * * @param rgb * @param width * @param height * @return * @throws IOException * @see http://en.wikipedia.org/wiki/Windows_bitmap */ public static byte[] encodeBMP(int[] rgb, int width, int height) throws IOException { int pad = (4 - (width % 4)) % 4; // the size of the BMP file in bytes int size = 14 + 40 + height * (pad + width * 3); ByteArrayOutputStream bytes = new ByteArrayOutputStream(size); DataOutputStream stream = new DataOutputStream(bytes); // HEADER // the magic number used to identify the BMP file: 0x42 0x4D stream.writeByte(0x42); stream.writeByte(0x4D); stream.writeInt(swapEndian(size)); // reserved stream.writeInt(0); // the offset, i.e. starting address of the bitmap data stream.writeInt(swapEndian(14 + 40)); // INFORMATION HEADER (Windows V3 header) // the size of this header (40 bytes) stream.writeInt(swapEndian(40)); // the bitmap width in pixels (signed integer). stream.writeInt(swapEndian(width)); // the bitmap height in pixels (signed integer). stream.writeInt(swapEndian(height)); // the number of colour planes being used. Must be set to 1. stream.writeShort(swapEndian((short) 1)); // the number of bits per pixel, which is the colour depth of the image. stream.writeShort(swapEndian((short) 24)); // the compression method being used. stream.writeInt(0); // image size. The size of the raw bitmap data. 0 is valid for uncompressed. stream.writeInt(0); // the horizontal resolution of the image. (pixel per meter, signed integer) stream.writeInt(0); // the vertical resolution of the image. (pixel per meter, signed integer) stream.writeInt(0); // the number of colours in the colour palette, or 0 to default to 2n. stream.writeInt(0); // the number of important colours used, or 0 when every colour is important; // generally ignored. stream.writeInt(0); // PALETTE // none for 24 bit depth // IMAGE DATA // starting in the bottom left, working right and then up // a series of 3 bytes per pixel in the order B G R. for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { int val = rgb[i + width * j]; stream.writeByte(val & 0x000000FF); stream.writeByte((val >>> 8) & 0x000000FF); stream.writeByte((val >>> 16) & 0x000000FF); } // number of bytes in each row must be padded to multiple of 4 for (int i = 0; i < pad; i++) { stream.writeByte(0); } } byte[] out = bytes.toByteArray(); bytes.close(); // quick consistency check if (out.length != size) throw new RuntimeException("bad math"); return out; } /** * Swap the Endian-ness of a 32 bit integer. * * @param value * @return */ private static int swapEndian(int value) { int b1 = value & 0xff; int b2 = (value >> 8) & 0xff; int b3 = (value >> 16) & 0xff; int b4 = (value >> 24) & 0xff; return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0; } /** * Swap the Endian-ness of a 16 bit integer. * * @param value * @return */ private static short swapEndian(short value) { int b1 = value & 0xff; int b2 = (value >> 8) & 0xff; return (short) (b1 << 8 | b2 << 0); }

    Where an error in my code? Is there another way to do the same thing?

    Why you want to use a bmp image?
    You can just use png, jpg or whatever of the original image is.
    If there is a situation where you need the bitmap image call http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/EncodedImage.html#getBi...

  • How to convert hex 8 bytes floating point double?

    Hello

    I want to know how to convert a string of 8 bytes of data double floating-point.

    data (HEX): 40 02 70 40 00 00 00 4F

    Thank you.

    DP

    This string of 8 bytes of data is actually a string? Are the characters in the string of letters or you have hex values? Ultimately you want to use the Type Cast:

  • Don't know how to read the results of netstat EI s list? If I received 860592506 bytes sent from 43421482 how to convert MB? And does this mean byte received?

    Don't know how to read the results of netstat EI s list? If I received 860592506 bytes sent from 43421482 how to convert MB? And does this mean byte received?

    Hello

    This shows the total number of bytes transmitted and received via the Ethernet card. This is the total of the amount of use up to this day.

    This includes all the Web sites you have visited and emails you sent, etc..

    You can calculate using one of the following methods:

    Method 1:

    860592506 / 1048576 = 820,72 MB

    Method 2:

    Multiply 860592506 with 9.53674316 * 10 ^-7 that will give us the result in mega bytes.

    860592506 bytes = 820 MB 9MB not, accept my apology for the miscalculation.
    Similarly 43421482 acroos = 40MB

  • How to convert an array of char byte array?

    Hello

    Someone can say, how can I convert Byte char []?

    Thank you

    What:

    data Byte [] =...

    Char [] charArr = (new String (data)) .toCharArray ();

    Rab

  • How to convert a single byte String?

    Purpose:

    Show a result byte on the BB 9900 screen.

    Question:

    How to convert a single byte String?

    Part of the code:

    byte value = con.cpu_config.elementAt (i)

    stop here

    String valuestring = new String (value);

    _rtf. SetText (valueString);

    If you know how to fix it, please share your idea.

    Thank you for your attention,

    String valuestring = new String (new byte [] {value}};)

    _data. Append (valueString);

    _rtf. SetText (_data.toSrting ());

    Solve it.

  • How to convert the following code in as3?

    As the title says... How to convert the following code to as3?... Thanks in advance.

    import flash.display.BitmapData;

    linkageId = "landscape";
    myBitmapData = BitmapData.loadBitmap (linkageId);


    MC = this.createEmptyMovieClip ("mc", 1);
    mc.attachBitmap (myBitmapData, 1);

    onMouseMove = function() {}
    myNewColor = "0 x" + myBitmapData.getPixel(_xmouse,_ymouse).toString (16);
    newColor.setRGB (myNewColor);
    selectedColor.colorValue.text = myNewColor;
    }
    selectedColor.swapDepths (_root.getNextHighestDepth ());
    newColor = new Color (selectedColor.sample);

    :

    var myBitmapData:landscape = new landscape (0,0);

    var bmp:Bitmap = new Bitmap (myBitmapData);
    addChild (bmp);

    stage.addEventListener (MouseEvent.MOUSE_MOVE, f);

    function f(e:MouseEvent):void {}
    var myNewColor:String = "0 x" + myBitmapData.getPixel(mouseX,mouseY).toString (16);
    newColorTransform.color = uint (myNewColor);
    selectedColor.sample.transform.colorTransform = newColorTransform;
    selectedColor.colorValue.text = myNewColor;
    }
    addChild (selectedColor);
    var newColorTransform:ColorTransform = selectedColor.sample.transform.colorTransform;

  • How to convert pictures from iPhoto?  I need general info and advice.  My library is huge (95 GB).  I am running OSX El Capitan 10.11.6 on iMac.

    How to convert pictures from iPhoto?  I need general info and advice.  I saw the help info but I am very nervous to take on this project, as my library is huge (95GB), organized in several events and albums.  My library is saved (Time Machine SimpleSave HD).  I am running OSX El Capitan 10.11.6 on iMac.

    Have you seen this document?   Updated Photos for OS X - Apple iPhoto support

    https://support.Apple.com/en-GB/HT204655

    Is your iPhoto Library Library on your system drive in the pictures folder? And you have a lot of free space on your system drive? The migration will need additional temporary storage.

    Then drag the iPhoto library icon pictures open to create a new library of Photos of her.

    Your albums appear unchanged in the Photos.  Events will appear as additional albums, because the pictures has no events.  See this link: How Photos handles content and metadata for iPhoto and Aperture - Apple Support

  • How to convert WAV, Alac

    How to convert WAV to ALAC files.

    1. Select Apple Lossless as your chosen import format using edit > Preferences > import settings.
    2. Choose files to convert.
    3. Use file > convert > create the Version Apple Lossless.

    TT2

  • How to convert .pdf to .epub

    Please see me step by step how to convert .pdf to .epub

    Hello PrasanW.

    Thank you for using communities Support from Apple. I see your message that you want to convert PDF files into ePub files.

    Read this article.

    Creating ePub with Pages files

    Have a great day.

Maybe you are looking for