Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: completely and utterly confused with NSImage + MySQL



Thanks for all the suggestions, but there's something else going on here. I had started out using [NSData bytes] to get the data into the database, and null bytes can't be the problem, because I use mysql_real_query to write the data, which can handle null bytes. Also, I use mysql_real_escape_string to escape any single quotes that might appear in the image data. This is never a problem with an uncompressed image, and it's always the SAME problem with an uncompressed image.... that is, I always get the same fraction of the image read from the database (or at least the same fraction is displayed in the image view) regardless of the actual image.... that is, the amount I see depends only on the level of compression, not the particulars of the image data.

Ahh.... and while typing this email, I've discovered that it has something to do with my implementation of drawRect !!!

Can someone answer this:

I have an image whose original size was 800x578. If I look at the info in the finder, the finder says 800x578. If I drop this image into an imageview, the image shows up as a tiny little thing (if it was saved with compression). If I override NSImageView's setImage so that I can inspect the image that's dropped, I see that [NSImage size] gives me a 61x44 image.... which is the size of the little tiny image that appears after the drop.

Why are these numbers different?

Thanks,
Eric

On Feb 26, 2006, at 1:27 AM, Hayden Stainsby wrote:

I'm using the MySQL-Cocoa framework (http://mysql- cocoa.sourceforge.net/) which has a method that makes use of the mysql_hex_string function to turn binary data into hex. After that you need to get the binary data back again (since NSImage won't read straight from a hex string).

Here's the code to get your image back again.

--------
		int			i;
		const char	*thumbnailHex;

		thumbnailHex = [thumbnailDataHex bytes];
		for (i = 0; i < strlen(thumbnailHex); i += 2)  {
			char	aByte, tChar[2];
			
			tChar[0] = thumbnailHex[i];
			tChar[1] = thumbnailHex[i+1];
			
			tChar[0] -= 0x30;
			if (tChar[0] >= 0x0a)
				tChar[0] -= 0x07;
			
			tChar[1] -= 0x30;
			if (tChar[1] >= 0x0a)
				tChar[1] -= 0x07;
			
			aByte = tChar[0] << 4;
			aByte = aByte | (tChar[1]);
			
			[thumbnailData appendBytes:&aByte length:1];
		}
		thumbnailImage = [[NSImage alloc] initWithData:thumbnailData];
--------

thumbnailDataHex is taken straight out of the MySQL database.

It's tested and works just fine for me. Let me know if I've missed anything here.

--
Hayden


#!/usr/bin/perl chop($_=<>);@s=split/ /;foreach$m(@s){if($m=='*'){$z=pop@t;$x =pop@t;push@t,$a=eval"$x$m $z";}else{push@t,$m;}}print"$a\n"; #http://occasionallyhuman.net/



On 25 Feb 2006, at 23:57, Eric Smith wrote:

That's pretty unsatisfying... let me ask another question. Is anyone on the list saving image data to a MySQL database? If so, how are you doing it? Writing a hex representation of the binary seems pretty safe.... but it doesn't work

Thanks,
Eric

On Feb 25, 2006, at 12:31 AM, Andrew Farmer wrote:

On 24 Feb 06, at 20:36, Eric Smith wrote:
If I take [tempData cString], run it through mysql_real_escape_string and then read it back into an image, using [[NSImage alloc] initWithData:...], the result is just a *portion* of the original image. How much? It depends on the level of compression. If I save an uncompressed image to the database, it comes back out as an entire image. What is going on here?!! Anyone have any ideas?

Two words for you: Null bytes.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/hds% 40caffeineconcepts.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >completely and utterly confused with NSImage + MySQL (From: Eric Smith <email@hidden>)
 >Re: completely and utterly confused with NSImage + MySQL (From: Andrew Farmer <email@hidden>)
 >Re: completely and utterly confused with NSImage + MySQL (From: Eric Smith <email@hidden>)
 >Re: completely and utterly confused with NSImage + MySQL (From: Hayden Stainsby <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.