title: UIImage from PNG binary from BLOB SQlite. Binary created from PHP fread. Null issue
body: <p>I am trying to load png images into UIImage from a SQlite database. The images are stored as binaries in a blob column. I've created the binaries using PHP fread, so I guess my first question is: is this a form of output that objective c will be able to use? If this isn't causing issues, then there must be an error somewhere in my objective c code.</p>
  
  <p>Here is how I load the data: </p>
  
  <pre><code>NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
  </code></pre>
  
  <p>When I NSLog data, I am able to see the numbers (a long list) for the 7 images I currently have. I assume I am getting the data from the column.</p>
  
  <p>What is strange is that when I send this data to an UIImage, I get nulls:</p>
  
  <pre><code>item.archThumb = [UIImage imageWithData:data];
  </code></pre>
  
  <p>or</p>
  
  <pre><code>UIImage *theimage = [[UIImage alloc]init];
  theimage =[UIImage imageWithData:data]; 
  </code></pre>
  
  <p>My second question is: am I missing an extra step?</p>
  
  <p>Here is the method I am using to read the items from the database:</p>
  
  <pre><code>-(void)readItems{
  if (!database) return; // earlier problems
  
  // build select statement
  if (!selStmt)
  {
      const char *sql = "SELECT items.arch_id, items.arch_name, arch_thumbs.thumbs_image FROM items LEFT JOIN arch_thumbs ON items.arch_id = arch_thumbs.thumbs_arch_id ORDER BY items.arch_name ASC;";
      if (sqlite3_prepare_v2(database, sql, -1, &amp;selStmt, NULL) != SQLITE_OK)
      {
          selStmt = nil;
      }
  }
  if (!selStmt)
  {
      NSAssert1(0, @"Can't build SQL to read items [%s]", sqlite3_errmsg(database));
  }
  
  // loop reading items from list
  int ret;
  while ((ret=sqlite3_step(selStmt))==SQLITE_ROW) 
  { // get the fields from the record set and assign to item
      // primary key
      NSInteger n = sqlite3_column_int(selStmt, 0); 
      Item *item = [[Item alloc] initWithPrimaryKey:n]; // create item
      // item name
      char *s = (char *)sqlite3_column_text(selStmt, 1);
      if (s==NULL) s = "";
      item.name = [NSString stringWithUTF8String:(char *)s];
  
      NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
  
      if (sqlite3_column_blob(selStmt, 2) != NULL) {
      item.archThumb = [UIImage imageWithData:data];
      NSLog(@"the image is:%@", item.archThumb);
      }
      else{
      NSLog(@"read a NULL image");
      }
  
      [items addObject:item]; // add to list
      [item release]; // free item
      [data release];
  }
  sqlite3_reset(selStmt); // reset (unbind) statement
  </code></pre>
  
  <p>}</p>