开发者

Acquiring/obtaining image from mysql database via php code for iphone app

开发者 https://www.devze.com 2023-04-04 05:40 出处:网络
I\'m uploading images to mySQL DB as a MediumBLOB since it allows me to upload images of upto sizes of 16 MB.

I'm uploading images to mySQL DB as a MediumBLOB since it allows me to upload images of upto sizes of 16 MB. In my iPhone app code, I'm just making a call to the PHP function which has the SQL query which says "select * from skin_table";

I need to apply skins to my app, so each of these skins have a name, like football, soccer, cricket, tennis, hockey, etc...

The names of each of the skins are being loaded through a picker view.

But, I need to fetch the images as well.

In short, I just want to download images from the server on to my iPhone app.

I'm 开发者_Python百科using NSXMLParser delegate methods:

In declaration file ".h":

 UIImage *currentSkin;
NSData *currentSkinData;

In the implementation file ".m":

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
   attributes: (NSDictionary *)attributeDict
{
     dictitem = [[NSMutableDictionary alloc] init];
     currentTitle = [[NSMutableString alloc] init];
     currentId = [[NSMutableString alloc] init];
     currentSkin = [[UIImage alloc]init];
}


-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
  if ([currentElement isEqualToString:@"id"]) {
    [currentId appendString:string];
  }
  else if ([currentElement isEqualToString:@"long_name"]) {
    [currentTitle appendString:string];
  } 
  else if ([currentElement isEqualToString:@"skin_image"]) 
  {
   //currentSkin = [[UIImage alloc]initWithContentsOfFile:string];
   //currentSkinData = UIImagePNGRepresentation(currentSkin);

    //NSUInteger len = [currentSkinData length];
    //Byte *byteData = (Byte*)malloc(len);
    //memcpy(byteData, [currentSkinData bytes], len);
   /* What goes here?? */
  }

I'm going to try doing this myself and will put up the code by editing this same post if I get through. I needed to get this done as soon as possible therefore I thought of asking some help, as I'd been sitting with this for the past two days that includes today.


UIImage *image1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];

This way you might be able to get the image.

0

精彩评论

暂无评论...
验证码 换一张
取 消