Converting ABRecordRef to bytes/NSData

Hi all,
I need to check the size of the individual record of the contacts stored in addressbook. so Is there anyway to convert the ABRecordRef into bytes or NSdata . So that I can check the size of the record ....
awaiting for the response .. Any Help would be greatly appreciated ....
Best Regards,
Mohammed Sadiq.

I have the way to resolve this question.
Image to bytes:
UIImage* pImage;
CFDataRef data_b = CGDataProviderCopyData(CGImageGetDataProvider(pImage.CGImage));
CFIndex len_b = CFDataGetLength(data_b);
const UInt8* pData_b = CFDataGetBytePtr(data_b);
bytes to image:
CGContextRef context=NULL;
CGColorSpaceRef colorSpace;
colorSpace = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(pData_b,
w,
h,
8, //bitspercomponent
w*4,
colorSpace,
kCGImageAlphaNoneSkipFirst);
if(context==NULL)
fprintf(stderr,"Contextnotcreated!");
CGColorSpaceRelease(colorSpace);
CGImageRef myImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
if (myImage != nil)
image_s = [[UIImage alloc] initWithCGImage: myImage];
CGImageRelease(myImage);
Hop it to help you.

Similar Messages

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • How do I convert a double-byte encoded file to single-byte ASCII?

    Hello,
    I am working with XML files (apparently coded in UTF-8) which encoded in double-byte characters.
    The problem is the characters for end of line: 00 0D 00 0A
    This double byte end of line is causing a problem with a legacy conversion tool (which deals with 0D 0A). The file itself contains no
    accented/international characters, so in principle converting to single-byte should not cause any problems.
    I have tried to convert this file with tools like native2ascii and the conversion tools that are part of Notepad++ but without
    any luck - the "00 0D 00 0A" are still present in the output
    Can anyone point me to a tool or some code that can convet this file into single-byte?
    Thank you.

    Amiens wrote:
    native2ascii.exe -encoding UTF-16 -reverse INPUT.xml OUTPUT.xml
    gives 00 00 0 0D 00 00 00 0A
    so clearly that is not the required output.What you've got there is UTF-16 encoded text that's been converted to UTF-16. Get rid of the "-reverse" option and you should see the result you expect.

  • Converting Japanese two Byte Character...

    Hi,
    I am doing a Scenario outbound from R/3.
    I am triggering the message via proxy using japanese language and sending to XI.
    In XI, we are getting the Mapping Error.
    Some records in the message contains single byte characters and some records having double byte characters.
    For single byte characters, XI is able to generate the target structure in the Mapping. But it is not able to convert the double byte characters to the target structure.
    Can any one help me to resolve this issue....
    Thanks in advance...
    Regards,
    Vasu

    Hi,
    Japanese data are Shift JIS encoded ? Maybe changing the encoding (or encoding declaration) could help ?
    Chris

  • How can I convert stream to byte and byte to stream

    I got a IInputStream from BackgroundDownloader operation, how can I convert it to byte array? I try to convert it to buffer and after that to bytes, but it's always throw exception.
    function decryptStream(inputStream, totalBytes) {
    var reader = new Windows.Storage.Streams.DataReader(inputStream);
    var iBuffer = reader.readBuffer(totalBytes);
    var bytes = Windows.Security.Cryptography.CryptographicBuffer.copyToByteArray(iBuffer);
    Could I have examples about that?

    Hi Jeft,
    In my program, I have a BackgroundDownloader to download an image. When we have result, I will convert it to bytes array.
    if (p.hasResponseChanged && imageStream == null) {
    imageStream = operation.getResultStreamAt(0);
    if (!p.hasResponseChanged && imageStream != null) {
    decryptStream(imageStream, p['bytesReceived']);

  • Converting Files to bytes

    hello
    Just want to know if there anyway to convert a text file to bytes. I can read the textfile but i want to convert them to bytes and store them.

    http://java.sun.com/j2se/1.4.1/docs/api/java/io/InputStream.html
    http://java.sun.com/j2se/1.4.1/docs/api/java/io/OutputStream.html
    Note that the Input[Output]Streams conserve extra byte information other than the content of a text.

  • Converting String to byte array

    Hi,
    There is a code for converting String to byte array, as follows:
         public byte[] toByteArray(String s)
              char[] c = s.toCharArray();
              int len = c.length;
              byte[] b = new byte[len * 2];
    for ( int i = 0 ; i < len ; i++ )
         b[i * 2] = (byte)(c);
         b[(i * 2) + 1] = (byte)(c[i] >> 8);
    return b;
    But this isn't doing the conversion properly. For example, for the � (euro) symbol, it converts to some other unreadable symbol. Also, same is the case for square brackets. Any idea why this' so? What's wrong with the above code?
    The encoding format is UTF-8.
    Thanks.

    > In fact, I tried with String.getBytes() too, but leads to the same problem, with those specific symbols.
    Did you try the String.getBytes(String charsetName) method?
    Both methods have been around since Java 1.1.
    It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of online documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • Convert mp3 to byte[],isThere api regard byte[] as param ret Player in jmf

    I convert .mp3 to byte[], is there any api regards byte[] as param return Player in jmf ;
    it's very important to me!!!!!!!!!!!!!!!!!!!!!!!

    It's very important to me that you clearly explain what you want to do.

  • Converting ASCII text (byte array ending in null) to a String

    Hi all,
    I am trying to convert a null terminated ascii string stored in a byte array to a java String. When I pass the byte array to the String constructor it
    does not detect/interpret the null as a terminator for the ascii string. Is this something I have to manually program in? ie Check for where the null is and then
    pass that subarray of everything before the null to the String constructor?
    example of problem
    //               A   B  C   D   null   F   (note F is junk in the array, and should be ignored since it is after null)
    byte[] asciiArray = { 65, 66, 67, 68, 0,  70 };
    System.out.println(new String(asciiArray, "UTF-8"));
    //this prints ABCD"sqare icon"F

    Why do you expect the null character to terminate the string? If you come from a C or C++ background, you need to understand that java.lang.String is not just a mere character array. It's a full-fledged Java object that knows its length without having any need for null terminator. So Ascii 0 is just another character for String object. To achieve what you want to do, you have to manually loop through the byte array and stop when you encounter a null character.

  • How to convert UIView object to NSData and vise-versa  for saving it in database using sqlite

    I am using sqlite for my project which stores all the data including text fields , id , and one UIVIew object in a column having BLOB datatype .
    Now while retriving the data i use
    const char *raw = sqlite3_column_blob(selectstmt, 3);
    int rawLen = sqlite3_column_bytes(selectstmt, 3);
    NSData *data = [NSData dataWithBytes:raw length:rawLen];
      view =[NSKeyedUnarchiver unarchiveObjectWithData:data];
    where data is NSData obj n view is UIView obj ,
    also while inserting data  i use ,
    NSData *data=[[NSData alloc]init];
        data=[NSKeyedArchiver archivedDataWithRootObject:view];
       // [data dataForView:notes.view];
        sqlite3_bind_blob(updateStmt, 2, [data bytes], [data length], SQLITE_TRANSIENT);
    But this is not working properly ...  the Data object is giving some length,
    while using the view the view object is null
    is there any other solution to do the same ?

    There's a ton of information here: [http://www.json.org/] and I can't believe you didn't find that site yourself.

  • Reading in any file and converting to a byte array

    Okay what I am trying to do is to write a program that will read in any file and convert it into a int array so that I can then manipulate the values of the int array and then re-write the file. Once I get the file into an int array I want to try and compress the data with my own algorithm as well as try to write my own encryption algorithm.
    What I have been looking for is code samples that essentially read in the file as a byte array and then I have been trying to convert that byte array into an int array which I could then manipulate. So does anyone have any sample code that essentially takes a file and converts it into an int array and then converts it back into a byte array and write the file. I have found code that is close but I guess I am just too new to this. Any help would be appreciated.

    You can read a whole file into a byte array like this:File f = new File("somefile");
    int size = (int) f.length();
    byte[] contents = new byte[size];
    DataInputStream in = new DataInputStream(
                              new BufferedInputStream(new FileInputStream(f)));
    in.readFully(contents);
    in.close();Note that you need to add in the proper exception handling code. You could also use RandomAccessFile instead of the DataInputStream.
    Writing a byte array to a file is easier; just construct the FileOutputStream, call write on it with the byte array, and close the stream.

  • How can I convert  AudioInputStream to  byte array ?

    Hi
    I want to convert audioinputStream to bytearry?
    i try like this
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
         int c = 0;
         while (true) {
         try {
                        c = audioInputStream.read();
                   } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
         if (c == -1)
         break;
         baos.write(c);
    but...
    java.io.IOException: cannot read a single byte if frame size != 1
    occur...
    plz help me..

    Hi,
    I haven't tried, but from the API doc I would suggest:
    Retrieve the frame size by
    int fs = audioInputStream.getFormat().getFrameSize();Allocate a byte array with at least this size and read full frames:
    byte[] buf = new byte[fs];
    int sz = audioInputStream.read(buf);Write also to your baos a full frame:
    baos.write(buf, 0, sz);

  • Converting Oracle 7-Byte Internal Date FOrmat to MM/DD/YYYY format.

    I can get the date stored in the database in 7-Byte Internal representation.
    I want to convert this number to mm/dd/yyyy format,using PRO*C-SQLDA(Method 4),overriding any NLS DATE Format.
    null

    Only Oracle Spatial questions
    here please.
    null

  • Converting 'little endian bytes' to short

    i need to convert to bytes in little endian format (low order byte first) into a short. i wrote an algorithm that i thought would solve this problem. it seems to work most of the time, however occassionally it does produce the wrong value. i was hoping someone out there could help me solve this problem
    public static short ByteToShort(byte one, byte two)
    // little endian format
    // remember LO then HO bytes
    short result = 0;
    result = (short) ((two << 8) + one);
    return result;
    }

    byte one and two are converted to int in the operation (before reconverted to short in the assignment).
    We must be extra careful here with possible signed bytes.
    public static short ByteToShort(byte one, byte two)
      // little endian format
      // remember LO then HO bytes
      short result = 0;
      result = (short) (((two << 8) & 0xFF00) | (one & 0x00FF));
      return result;

  • How to Convert Integer to byte[n]!Help

    I have a Integer 314,Convert to hex is 0x13a,I want to convert to byte[2],and byte[0] equals 0x13 and byte[1] equals [0x30];I use this method convert byte[4],
    int iVal = 314;
    byte [] bVals = new byte[4];for( int i=0; i<4; i++ ) { 
    bVals<i> = (byte)(iVal & 255);
    iVal >>= 8;
    Not I want to result.Please help!

    Try:
    int iVal = 0x01FF03F0;
    byte [] bVals = new byte[4];
    for(int i=3; i>=0; i--) {
        bVals[i] = (byte)(iVal & 255);
        iVal >>= 8
    //print results
    for (int i = 0; i < 4; i++) {
       int temp = bVals[i] & 0xFF;  // avoid displaying negative numbers
       System.out.println("byte " + i + " = " +  Integer.toHexString(temp));
    }

Maybe you are looking for

  • Problem printing borderless PDF w/ Snow Leopard + Acrobat Pro 9 + MS Office

    Create a borderless Word doc in MS Office 2008 (text or images go all the way to the edge). Using OS X 10.5, you can select "Print to PDF" and it will print a borderless PDF. Beautiful. Using OX X 10.6 (Snow Leopard), that's now impossible because Sn

  • XI Adapter Framework Error in SXMB_MONI

    Hi Experts,   i am getting below error in MONI. Could any one please advice me what is the problem... *<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>* *- <!--  Inbound Message*   --> - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30"

  • Strange error of CALL FUNCTION within Method

    Hi all, i'm facing a very strange problem. Some Function Modules can't be called from within a method and a dump appears with the following message CALL_FUNCTION_CONFLICT_LENG (CX_SY_DYN_CALL_ILLEGAL_TYPE). Here's an example: I've created a normal cl

  • How do you fix the screen

    you get like a scalpel or a sharp knife and cut the screen open and replace the screen

  • Can anyone help me with raster to vector and transparent background?

    In Photoshop CS3 I created a three dimensional logo (beveled, drop shadow, etc.) and want to covert it to an Illustrator vector file (and then to an EPS) with no white background. When I "open" the flattened .psd file (that has no background) in Illu