Re: copy in WebView
On 13.10.2012, at 21:00, Kyle Sluder wrote: > Could you instead broaden your test to "my WebView or any of its > descendants is first responder?" or simply use directly the WebView on the responderchain. Because I had similar problems like Gerriet concerning finding a selected string or zooming the WebView (text only or the whole WebView including images) I use the following code (not using the dangerous WebHTMLView question): - (WebView *) currentRespondingWebView { id firstResponder = [[NSApp keyWindow] firstResponder]; // let's search for a WebView in the responderchain for( id frsp=firstResponder; frsp!=nil; frsp=[frsp nextResponder] ){ NSLog(@"frsp = %@ --> %@", [frsp class], [frsp superclass] ); // test only if( [frsp isKindOfClass:[WebView class]] ) return frsp; // found a WebView } return nil; // no success } And if you have the WebView you have all you need, e.g. the selectedDOMRange. BTW the test output is: frsp = WebHTMLView --> NSControl frsp = WebClipView --> NSClipView frsp = WebDynamicScrollBarsView --> NSScrollView frsp = WebFrameView --> NSView frsp = WebView --> NSView Gerriet, do you remember what you wrote on Mar 24 2010 ? performFindPanelAction: in WebView Heinrich Giesen ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Keeping grayscale image grayscale
Jonathan Taylor wrote: > I'm working with 16-bit grayscale images, and for the most part I'm just > manipulating bits within NSBitmapImageRep objects. However for convenience it > would be nice to do some stuff with NSImages, particularly when rescaling and > suchlike. The problem is that whenever I draw into such an NSImage it gets > converted to 3x8 bit RGB. Is there a simple way I can force things to stay > grayscale, or am I fighting a losing battle here. You are not fighting a losing battle, you use the wrong methods to create an NSBitmapImageRep with properties you want. If you want to create an NSImage/NSImageRep with special properties: there is a rule of thumb: don't use lockFocus. --> Re: bad behavior from unlockFocus on 10.6 by Ken Ferry. Another rule of thumb is: if you need -[NSImage TIFFRepresentation] you do something wrong. (There are of course counterexamples). The following code does (I hope so) what you want: NSImage *srcImage = [[NSImage alloc] initWithContentsOfFile:thePath]; // create a new empty NSBitmapImageRep NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide: (NSInteger)newWidth pixelsHigh: (NSInteger)newHeight bitsPerSample: 16 samplesPerPixel: 1 hasAlpha: NO// YES is not supported isPlanar: NO colorSpaceName: NSCalibratedWhiteColorSpace bytesPerRow: 0 bitsPerPixel: 0]; //Now save the current NSGraphicsContext and set a new one [NSGraphicsContext saveGraphicsState]; NSGraphicsContext *newContext = [NSGraphicsContext graphicsContextWithBitmapImageRep: newRep]; [NSGraphicsContext setCurrentContext: newContext]; [srcImage drawInRect:NSMakeRect( 0, 0, [newRep pixelsWide], [newRep pixelsHigh] ) fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; // Restore the previous graphics context and state. [NSGraphicsContext restoreGraphicsState]; and see what the newRep looks like: NSLog( @"newRep is:%@", newRep ); This code creates a 16 bit grayscale image whatever the source image is. Good luck Heinrich ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Cocoa-dev Digest, Vol 8, Issue 148
Send Cocoa-dev mailing list submissions to cocoa-dev@lists.apple.com To subscribe or unsubscribe via the World Wide Web, visit http://lists.apple.com/mailman/listinfo/cocoa-dev or, via email, send a message with subject or body 'help' to cocoa-dev-requ...@lists.apple.com You can reach the person managing the list at cocoa-dev-ow...@lists.apple.com When replying, please edit your Subject line so it is more specific than "Re: Contents of Cocoa-dev digest..." Today's Topics: 1. NSProgressIndicator tintcolor (Gustavo Pizano) 2. UIWebView: Scale factor (Phillip Mills) 3. First Responder (koko) 4. Re: First Responder (Kyle Sluder) 5. Re: First Responder (Graham Cox) 6. Re: First Responder (koko) 7. Re: First Responder (Graham Cox) 8. Re: First Responder (koko) 9. NSWindowController (koko) 10. Re: First Responder (Kyle Sluder) 11. Re: NSWindowController (Louis Demers) 12. Re: First Responder (koko) 13. Re: First Responder (Kyle Sluder) 14. Re: NSWindowController (koko) 15. Re: First Responder (koko) 16. Re: NSWindowController (koko) 17. XCode question: "Copy Header" build step doesn't work for my Framework target. (Motti Shneor) -- Message: 1 Date: Fri, 25 Feb 2011 23:31:11 +0100 From: Gustavo Pizano Subject: NSProgressIndicator tintcolor To: Cocoa Developer Message-ID: <46fd55fc-2f52-4c36-be2e-24577d822...@gmail.com> Content-Type: text/plain; charset=us-ascii Hello all. Im just wondering why changing the tint color using the setControlTint of the progress bar to NSGraphiteControlTint doesn't has any effect, I keep seeing that aqua colors... I have tried finding answers online but it seems everybody has that problem.. or everybody is doing something wrong.. hehehe.. including me. what am I doing wrong? here is the code that I use to create the progress indicator progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(10, 5, 280, 8)]; [progressIndicator setMinValue:0.0f]; [progressIndicator setMaxValue:100.0f]; [progressIndicator setDoubleValue:50.0f]; [progressIndicator setIndeterminate:NO]; [progressIndicator setBezeled:YES]; [progressIndicator setControlTint:NSGraphiteControlTint]; [progressIndicator setDisplayedWhenStopped:YES]; [self.view addSubview:progressIndicator]; Thx Gustavo -- Message: 2 Date: Fri, 25 Feb 2011 17:35:30 -0500 From: Phillip Mills Subject: UIWebView: Scale factor To: Cocoa Developers Message-ID: <752698d2-af22-4863-9ff7-b040a46f0...@acm.org> Content-Type: text/plain; charset=us-ascii I'm loading files into a UIWebView on an iPad and need to be able to scroll them programatically to positions in the displayed files. Many of these files are PDF, but generally it could be any of the types supported by loadRequest. I'm able to do what I want using JavaScript if I set up my UIWebView with "scalesPagesToFit = NO". However, doing that looks terrible. The problem with allowing automatic scaling is that I know my scrolling requirements in screen units but JavaScript interprets them as document units. Depending on the original file and the iPad orientation the error factors I've seen are in the 20-to-40% range. How do I set "scalesPagesToFit = YES" and know what scaling was applied? (I have a truly terrible hack in mind but I hope to be saved from that madness. :-) ) -- Message: 3 Date: Fri, 25 Feb 2011 22:31:40 -0700 From: koko Subject: First Responder To: Cocoa Developers Message-ID: <63601f8a-bc9f-488f-a299-610af3c73...@highrolls.net> Content-Type: text/plain; charset=us-ascii I connect a menu item to an action in first responder. The action is defined in a .h and .m in the project In applicationDidFinishLaunching I alloc, init and retain an object that contains the action connected to the menu item in first responder. At run time the menu item is not enabled. I don't get it. I guess this is basic but I have done this before with no problem. Advice please. -koko -- Message: 4 Date: Fri, 25 Feb 2011 21:59:46 -0800 From: Kyle Sluder Subject: Re: First Responder To: koko Cc: Cocoa Developers Message-ID: <84c1b585-db83-49e5-ad99-01b85efaf...@gmail.com> Content-Type: text/plain; charset=us-ascii On Feb 25, 2011, at 9:31 PM, koko wrote: I connect a menu item to an action in first responder. The action is defined in a .h and .m in the project In applicationDidFinishLaunching I alloc, init and retain an object that contains the action connected to the menu item in first responder. At run time the menu item is not enabled. I don't get it. Is the object in the responder chain at all? The menu item can't magically know about the object; it needs to look through the re
Re: Redirect NSLog to stdout
On 29.06.2010, at 18:12, Tito Ciuro wrote: ... Instead, is there a way to configure NSLog() so that it redirects to stdout instead of stderr? google for Quietlog NSLog and you find some hints ( this is one of them: http://borkware.com/ quickies/single?id=261 ) how to replace NSLog with a function with identical syntax for a shorter (or a more verbose) output, which can also be written to stdout or stderr or whatever you want. --Heinrich -- Heinrich Giesen gies...@acm.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSBezierPath linewidth not correct
On 03.01.2010, at 00:45, Rob Keniger wrote: It will probably be easier to create an NSAffineTransform and translate the whole context by 0.5px, so all drawing is offset without you needing to fiddle with individual values. Just a hint: NSBezierPath has a method which allows to use NSAffineTransform for this even outside a rendering/drawing process: Description of transformUsingAffineTransform, a method of NSBezierPath: Transforms all points in the receiver using the specified transform. - (void)transformUsingAffineTransform:(NSAffineTransform *)aTransform Example: NSBezierPath *bPath = // create a path // construct the complete path NSAffineTransform *transform = [NSAffineTransform transform]; // move all coordinates to the center of the pixels [transform translateXBy: 0.5 yBy: 0.5 ]; [bPath transformUsingAffineTransform:transform]; // bPath is now ready for drawing -- Heinrich Giesen gies...@acm.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSImage resizing
Hi, On 15.01.2009, at 09:31, Parimal Das wrote: i am getting the following output error- 2009-01-15 13:43:09.313 te[747:10b] NSImage 0x117340 Size={32, 32} Reps=( NSIconRefBitmapImageRep 0x117e30 Size={128, 128} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=128x128 Alpha=YES Planar=NO Format=0, NSIconRefBitmapImageRep 0x11cdd0 Size={48, 48} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=48x48 Alpha=YES Planar=NO Format=0, NSIconRefBitmapImageRep 0x118280 Size={32, 32} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=32x32 Alpha=YES Planar=NO Format=0, NSIconRefBitmapImageRep 0x11ce80 Size={16, 16} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=16x16 Alpha=YES Planar=NO Format=0 ) 2009-01-15 13:43:09.314 te[747:10b] OK1 2009-01-15 13:43:09.315 te[747:10b] NSIconRefBitmapImageRep 0x117e30 Size={384, 384} ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=128x128 Alpha=YES Planar=NO Format=0 Segmentation fault -> program exited this segmentation fault is coming just before the image writing step (notice check 3 is not coming). ie program is crashing before the step [[bitmapImageRep2 representationUsingType:NSJPEGFileType properties:nil] writeToFile:destPath atomically:YES]; I tested my code in Tiger and in Leopard and it works well in both systems. My guess is, that the Segmentation fault is due to an invalid (over released?) destPath. The debugger may tell you more about the bug. i am really clueless about why it is happening also there is a big difference between general NSImage and what i am getting in myIcon (see its a mixture of 4 images as in the .icn files) No, it's ok. The NSImage is a container of zero, one or more NSImageReps. It's typical for icon images to have several representaions of different pixelsizes. Greetings Heinrich -- Heinrich Giesen gies...@acm.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSImage resizing
On 09.01.2009, at 15:11, Parimal Das wrote: in my application i need to resize a .jpg image through a command line What does it mean: "resize" ?. Every NSBitmapImageRep has two sizes: a (print-)size which says how long width and hight (expressed in inch, cm or printerpoints or ...) of the depicted (printed) image are. This value can be set (changed) with -setSize:. And it has a (storage-)size which says how many pixel the image has expressed as a dimensionless number. The connection between these two "sizes" is the "resolution". Changing the pixelnumbers results in a rendering process. Next point: An icon (NSImage) is a container of several NSBitmapImageReps. You have to select the one that fits best. That lets me make a proposal which is close to your first try: NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:filePath]; NSSize imageSize = { 384.0, 384.0 }; // in points (384 pts = 512 px at 96 dpi resolution) [icon setSize:imageSize]; NSBitmapImageRep *bitmapImageRep = (NSBitmapImageRep *)[icon bestRepresentationForDevice:nil]; [bitmapImageRep setSize:imageSize]; // <--- do not forget !!! [[bitmapImageRep representationUsingType:NSJPEGFileType properties:nil] writeToFile:destPath atomically:YES]; -- Heinrich Giesen gies...@acm.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: dragging images to the finder
On 12.01.2009, at 05:50, Nick Zitzmann wrote: Assuming you are trying to create a picture file here, you have to use the pasteboard type "CorePasteboardFlavorType 0x6675726C" to get the Finder to accept the drag, and it must contain a file URL string pointing to the source image that you must write to the disk somewhere. You do not really have to create some data for this PB flavor type. It is much simpler. You do not even have know what such a flovor means (I guess it is part of AppleScript). Do this: somewhere tell the pasteBoard what types you use for dragging: NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard]; [pb declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self]; And eventually (I hope you know where the image is an the disc) you feed the pasteBoard with: BOOL rtn = [pb setPropertyList:[NSArray arrayWithObject:locationOfTheImage] forType:NSFilenamesPboardType]; (Yes, you need an NSArray of files! ). Now finally have a look at the dragPasteboard. It contains data for: NSFilenamesPboardType NeXT filename pasteboard type CorePasteboardFlavorType 0x6675726C ( 'furl' ) Apple URL pasteboard type (internal name for NSURLPboardType) CorePasteboardFlavorType 0x68667320 ( 'hfs ' ) Do not underestimate the power of the PasteBoardServer! Godd luck, Heinrich -- Heinrich Giesen gies...@acm.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Fastest way to resize an image?
Hi, On 22.11.2008, at 19:36, Jean-Nicolas Jolivet wrote: Problem is... the ImageRep technique works well when I'm just scaling an image..it's quite fast too, however I am also cropping (in some cases)... and unfortunately, without the "fromRect" parameter, it's pretty much impossible to crop... for a more comfortable drawing method you need an extra NSImage, but the overhead is very small. Replace [self drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide], [sourceRep pixelsHigh])]; (as you already noticed there is a typo: "self" is wrong, it should have been "sourceRep", sorry ) with: (written in mail) NSImage *tmpImg = [[NSImage alloc] initWithSize:NSZeroSize]; [tmpImg addRepresentation: sourceRep]; [tmpImg drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide], [sourceRep pixelsHigh]) fromRect:cropRect // or NSZeroRect when using the whole image operation:NSCompositeSourceOver fraction:1.0]; If the newRep shall have the same resolution as the source, we can do it with: float dpiX = 72.0*[sourceRep pixelsWide]/[sourceRep size].width; // source x resolution NSSize size = [newRep size]; size.width = 72.0*[newRep pixelsWide] / dpiX; [newRep setSize:size]; (similar setting the y resolution) Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Fastest way to resize an image?
Hi, On 20.11.2008, at 09:05, Jean-Nicolas Jolivet wrote: I have a bunch of images to resize. anyway, right now I am loading an NSBitmapImageRep with the imageRepFromFile: method... then creating a new, empty NSImage based on the image size that I want to resize to (using initWithSize:) and I draw the BitmapImageRep on this image (while the focus is locked on the NSImage)... I understand that you are not happy with this way, I call this way the old way, which is now outdated but not deprecated, because since Tiger you can draw directly into an NSBitmapImageRep. (The above way first creates --lockfocus does it-- and then draws into an NSCachedImageRep, from which a new NSBitmapImageRep can be made via TIFFRepresentation.) I usually use the following code (or a similar one) which respects the size (resolution) of the sourceImage reliably! (Searching in this forum for graphicsContextWithBitmapImageRep: will give more hints.) // first load the sourceImage NSBitmapImageRep *sourceRep = [[NSBitmapImageRep alloc] initWithData: ..dataFromFile ..]; NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:[sourceRep pixelsWide] // or a new value pixelsHigh:[sourceRep pixelsHigh] bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES // must have alpha! isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0 ]; [NSGraphicsContext saveGraphicsState]; NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:newRep]; [NSGraphicsContext setCurrentContext:context]; // do not use drawAtPoint: !! it does not respect resolution due to a bug [self drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide], [sourceRep pixelsHigh])]; [NSGraphicsContext restoreGraphicsState]; [newRep setSize:[sourceRep size]]; // this sets the resolution of the source [newRep autorelease]; // if needed Instead of [sourceRep pixelsWide] you should set the new number of pixels. This value must be the same in pixelsWide: and in the drawRect. You see: NSImage is not used because we don't need it. If more flexible drawOperations are waanted, I use a new temporary NSImage and remove it as soon as possible. My tests showed a time speedup of at least a factor of 5. BTW: the connection between size, pixelnumbers and resolution is: size.width = 72.0*pixelsWide / resolutionX size.height = 72.0*pixelsHigh / resolutionY (size has the dimension of a length and the unit 1/72 inch; resolution has the dimension "dots per length" and the unit "dots per inch"; pixelsWide, pixelsHigh are dimensionless numbers.) good luck Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: BOOL value in Dictionary
Hi, besides what Ken Thomases and Graham Cox already said, I have a remark concerning programming style: if ( colorSwitch == YES) { [colorBox setState:NSOnState]; } else { [colorBox setState:NSOffState]; } It is bad to test a Boolean value with "colorSwitch==NO" and it is a very very bad habit to test a Boolean value with "== YES" (there is a longer thread in this forum). It is not that difficult to smoothly deal with Boolean expressions. It's not a question of efficiency but a question of style, so the above snippet is equivalent (and more Boolean-like): [colorBox setState: colorSwitch ? NSOnState : NSOffState]; Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: JPEG compression in TIFF files. NSTIFFCompressionJPEG
On 13.11.2008, at 00:34, Alexander Shmelev wrote: Our customer asks us to save images in TIFF files with JPEG compression. But in NSImage documentation is written that JPEG compression is no longer supported. Why Apple decided to stop support JPEG compression in NSImage class? The difficulties with JPEG-compression in TIFF-files reach back to 1995. In that year a draft <http://www.remotesensing.org/libtiff/TIFFTechNote2.html> from the TIFF-people (formerly Aldus, now Adobe) was published and give a deep look into these difficulties. One of the first sentences is: ... TIFF writers are strongly discouraged from using the 6.0 JPEG design In another document <http://netghost.narod.ru/gff/graphics/summary/ tiff.htm> search for a statement by Tom Lane (the jpeg guru) where he explains : TIFF 6.0 added JPEG to the list of TIFF compression schemes. Unfortunately, the approach taken in the 6.0 specification is a very poor design. A new design has been developed by the TIFF Advisory Committee. If you are considering implementing JPEG in TIFF, I strongly urge you to follow the revised design described in TIFF Tech Note #2 rather than that of the 6.0 spec. Meanwhile some fixes have been made. But we still have TIFF 6.0 and maybe the long expected TIFF 7.0 will never come. The Adobe - TIFF story has never been a love story. To directly use the current TIFF library tiff-3.8.2 may help if really needed. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: A way to disable all tooltips in an Application?
On 30.10.2008, at 13:41, Vijay Malhan wrote: Hello All, Is there a way to disable all tooltips in an Application. Regards, Vijay Here: <http://www.macworld.com/article/55202/2007/02/termtooltips.html> and here <http://www.macosxtips.co.uk/index_files/disable-tooltips- safari-firefox.html> hints are given to use NSInitialToolTipDelay in user defaults. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: image type of the AdressBook image data
On 05.08.2008, at 10:03, Wayne Shao wrote: The imageData method returns NSData*. Is there anyway to know the image type (e.g, PNG, TIFF, or JPEG) of the data? besides that what Ken Ferry wrote you may also use (as I do) a low level way to determine the image type: check for the magic number of image data. const unsigned char *bytes = [imageData bytes]; //NSLog( @"%02x %02x %02x %02x ", bytes[0], bytes[1], bytes[2], bytes[3] ); BOOL isTIFF_BigEndian = (bytes[0]=='M') && (bytes[1]=='M'); BOOL isTIFF_LittleEndian = (bytes[0]=='I') && (bytes[1]=='I'); BOOL isJPEG= (bytes[0]==0xff) && (bytes[1]==0xd8) && (bytes[2] ==0xff); BOOL isPNG = (bytes[0]==0x89) && (bytes[1]=='P') && (bytes[2] =='N') && (bytes[3]=='G') && (bytes[4]==0x0d) && (bytes[5]==0x0a) && (bytes[6] ==0x1a) && (bytes[7]==0x0a); BOOL isGIF = (bytes[0]=='G') && (bytes[1]=='I') && (bytes[2] =='F'); BOOL isPDF = (bytes[0]=='%') && (bytes[1]=='P') && (bytes[2] =='D') && (bytes[3]=='F') && (bytes[4]=='-'); BOOL isBMP = (bytes[0]=='B') && (bytes[1]=='M'); BOOL isICNS= (bytes[0]=='i') && (bytes[1]=='c') && (bytes[2] =='n') && (bytes[3]=='s'); The Carbon/Cocoa functions and methods do nothing else, they test the magic number. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: File types opened by NSDocument architecture
On 22.07.2008, at 09:50, Tom Bernard wrote: /* + (NSArray *)readableTypes { return [NSArray arrayWithObjects:@"TIFF", @"tiff", @"TIF", @"tif", @"GIF", @"gif", @"JPEG", @"jpeg", @"JPG", @"jpg", @"png", nil]; } */ My application needs to open the above listed file types. When I am in Finder and I drag and drop one one of these files to my application, the file opens. When I choose 'Open...' from my application's 'File' menu, only .tif and .psd files are selectable in the open dialog. Big misunderstanding; with readableTypes you have to return: An array of NSString objects representing the readable document types. *document types* not *file/image types* In your info.plist you define 2 doctypes "Adobe Photoshop file" and "Large Image Viewer GIF Document" wich are responsible for files with the extensions "psd" and "gif". Create in Xcode (info -> Properties) another doctype which has as CFBundleTypeExtensions a blank (?) separated list of the above image types. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: setting image for person in address book
On 19.07.2008, at 13:35, Vijay Kanse wrote: NSData *imageData = [[NSData alloc] initWithContentsOfFile:@"file://localhost/volumes/DATA/image/ play.tiff"] ; I am tracing program and I am not getting any value in imageData. In your program the parameter of -initWithContentsOfFile: is not a file, it's an URL. Try to read instead with -initWithContentsOfURL: -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Setting DPI of image data
On 11.07.2008, at 05:37, Graham Cox wrote: I'm using NSBitMapImageRep's -representationUsingType:properties: method to convert data to JPEG, TIFF, etc. I'd like to be able to specify the DPI of the image. I can calculate the right number of pixels needed for a given DPI OK, but the image always comes up as having 72 dpi when opened in another app. Is there a way to set this property at this level, or am I forced to drop down into Image I/O? If you create image data of Type jpeg, tiff, png, etc from a sourceRep (NSBitMapImageRep) with -representationUsingType:properties: these data contain the number of pixels *and* the resolution of the sourceRep. If you want a special resolution you have to set that value in the sourceRep. But you can't set the resolution directly in NSBitMapImageRep with something like -setResolutionX:resolutionY: You have to set the size of the rep! Because of: size.width = 72.0*pixelsWide / resolutionX size.height = 72.0*pixelsHigh / resolutionY (size has the dimension of a length and the unit 1/72 inch; resolution has the dimension "dots per length" and the unit "dots per inch"; pixelsWide, pixelsHigh are dimensionless numbers.) there is no difference between setting the resolution and setting the size. If the rep shall have a resolution of 72 dpi, the size must be set to (pseudocode) size = (pixelsWide, pixelsHigh); (Because this is the default, you need not do so.) This is a bit confusing. A lot of programmers think that size and number of pixels are one and the same with different words. The values are indead *numerically* the same, but only for a resolution of 72 dpi. If the rep shall have a resolution of 144 dpi, the size must be set to size = (pixelsWide/2.0, pixelsHigh/2.0); For these settings in my programs I use a category for NSBitMapImageRep which does the job. One other point. Let's have a sourceRep with a resolution of 100 dpi and this sourceRep is stored as png-file (data come from -representationUsingType:properties:) then Preview.app will show a resolution of 99.9998 dpi which is correct! This happens because in png-files the resolution is stored as int with the unit "dots per meter": res [dots per meter] = (int)(1 / 2.54) = 3937 or: res [dots per inch] = 3937*0.0254 = 99.9998 Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Problem copying pdfImageRep to bitmapRep.
On 10.07.2008, at 20:19, Graham Cox wrote: I want to render pdf data into a bitmap as part of an export conversion. My pdf data is good (I can save it as a pdf file and that comes up OK). My bitmap is good, but it's blank. follows the code . If I understand the code and what you want to achieve it is clear that the result is blank (could also be a random noise) because you created an empty NSBitmapImageRep (bmRep ) and no one draws into the bmRep. You say: "but I did a lockFocusOnRepresentation:bmRep" and expect that drawing goes into the bmRep. This is a big but common misunderstanding. A drawing (within a lockFocus --- unlockFocus) never changes/overwrites an NSImageRep contained in the NSImage. With lockFocus you cannnot draw/write into an NSBitmapImageRep. Instead always an NSCachedImageRep is created which is only good for drawing. A resulting NSBitmapImageRep can be created from this NSCachedImageRep with the help of - TIFFRepresentation. In your code you don't need the NSBitmapImageRep (bmRep ), it is absolutely useless. The following code (modification of your code) could do it: - (NSBitmapImageRep*) bitmapWithResolution:(int) dpi { NSPDFImageRep* pdfRep = [NSPDFImageRep imageRepWithData:[self pdf]]; NSAssert( pdfRep != nil, @"couldn't create pdf image rep"); NSSize bmSize = [self drawingSize]; NSRect destRect = NSZeroRect; destRect.size = bmSize; NSImage* bmImage = [[NSImage alloc] initWithSize:bmSize]; [bmImage lockFocus]; [pdfRep drawInRect:destRect]; [bmImage unlockFocus]; [bmImage autorelease]; return [NSBitmapImageRep imageRepWithData:[bmImage TIFFRepresentation]]; } But there is a way to draw into an NSBitmapImageRep. You have to use -graphicsContextWithBitmapImageRep: from NSGraphicsContext. This has the advantage that you can set several parameters of the newly created NSBitmapImageRep e.g. pixelsWide, pixelsHigh and size which results in a resolution (dpi) of your choise. In your case I would prefer this way to create a bitmap from a PDF file. Examples of the use of -graphicsContextWithBitmapImageRep: are in this list. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Manipulating images with meta-data
On 03.06.2008, at 21:00, Randall Meadows wrote: I'm about to resort to using a third-part solution (jpegtran and jpegexiforient) that I've found, but Except that I'm not going to be able to use jpegexiforient, because the image file apparently isn't in the correct form it wants. This test fails: /* Read File head, check for JPEG SOI + Exif APP1 */ for (i = 0; i < 4; i++) exif_data[i] = (unsigned char) read_1_byte(); if (exif_data[0] != 0xFF || exif_data[1] != 0xD8 || exif_data[2] != 0xFF || exif_data[3] != 0xE1) return 0; since the 4th byte (exif_data[3]) is 0xE0. I don't really know what that means, other than I guess I'm back to square one trying to rotate an image, and update and preserve all the meta-data. That means that jpegexiforient expects an APP1 marker (Exif marker) as first jpg marker behind the SOI (0xffd8) marker. But this is not always the case. Very often jpg data start with an APP0 (JFIF or JFXX) marker or they may have none of them. Some start with an APP0 marker followed by an APP1 (Exif) marker, which is not allowed, but who cares; Adobe doesn't care and writes both markers in the same file. Bill Bumgarner wrote: According to... http://www.astro.keele.ac.uk/oldusers/rno/Computing/File_magic.html ... the fourth byte should be 0xE0 in a JPEG. A bit of googling reveals that the first four bytes might be either FFD8FFE0 or FFD8FFE1. Forget that link, it is a bad second hand literature. The given magic number for jpg file (and also that for PNG files) is wrong. According to the original text (starting at http://www.w3.org/Graphics/JPEG/ and http://www.w3.org/Graphics/JPEG/itu-t81.pdf) a jpg file is identified by the first 3 (three) digits 0xFFD8FF, which means: the data have to start with the SOI marker followed by the next marker. Only these three bytes make the magic number. There is no rule which marker has to follow. (I wrote my own jpg scanner and experienced a lot of surprices! ) I'm about to resort to using a third-part solution This is a good idea! My favourite program is exiftool by Phil Harvey: http://www.sno.phy.queensu.ca/~phil/exiftool/ exiftool -Orientation=8 -n a.jpg will do the job. Good luck Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSImage display quality and zooming
On 28.05.2008, at 03:16, also wrote: I've created a custom NSView that displays an image and allows the user to zoom in and out. The view works in general, but the quality of the image displayed is not what I expect. When I zoom in even slightly on a high resolution image (300 dpi, 500x500) the image is grainy and pixelated. this is one of the FAQ in this list. The solution is: image = [[NSImage alloc] initWithContentsOfURL:url]; [image setDataRetained:YES]; // <-- The docs say: - (void)setDataRetained:(BOOL)flag Retention of the source image data is important if the source of the image data could change, be moved, or be deleted. Data retention is also useful if you plan to resize an image frequently; otherwise, resizing occurs on a cached copy of the image, which can lose image quality during successive scaling operations. With data retention enabled, the image is resized from the original source data. good luck -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSRectFillListWithColors question
On 14.05.2008, at 15:32, Davide Scheriani wrote: I was playing around with the Graphics drawing method and I wanted to use NSRectFillListWithColors. . My small problem is that it accept C-style arrays not NSArray. What can I do? Do exactly what the description of this function says; void NSRectFillListWithColors(const NSRect *rects, NSColor **colors, int count) I used this function to draw the colortables of GIF, PNG or BMP- imgaes and it looks something like: NSRectrectList[256]; // long enough for a color table NSColor *colorList[256]; rectList[0] = NSMakeRect( 0, 0, 26, 16 ); // is it flipped ? rectList[1] = NSMakeRect( 32, 0, 26, 16 ); rectList[2] = NSMakeRect( 64, 0, 26, 16 ); colorList[0] = [NSColor blackColor]; colorList[1] = [NSColor whiteColor]; colorList[2] = [NSColor redColor]; NSRectFillListWithColors( rectList, colorList, 3 ); Good luck Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: 1-bit NSBitmapImageRep?
Hi, Can't I just fill or stroke a path with that rep as a context? no, you can't. If you try to create a context with: [NSGraphicsContext graphicsContextWithBitmapImageRep:oneBitRep]; it is not accepted. The errormessage is: CGBitmapContextCreate: unsupported parameter combination: 1 integer bits/component; 1 bits/pixel; 1-component colorspace; kCGImageAlphaNone If you really need a 1-bit imageRep and drawing is complicated (bezierPath, and not just a color reduction of a given image) I would do it in two steps: 1: use a 8 bit rep with 1 component and a WhiteColorSpace (or BlackColorSpace); do the drawing. 2: iterate over the bitmap of this new imageRep, use the gray pixel to convert it to black or white and set this 1 bit pixel in a corresponding 1 bit imageRep (this means: filling it yourself) I wrote a small test application to explore the using (limits) of +graphicsContextWithBitmapImageRep: I think I extend it to create a 1 bit imageRep. More in private mails. Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: 1-bit NSBitmapImageRep?
On 17.04.2008, at 08:32, Graham Cox wrote: Is it possible to create a 1-bit (black and white) NSBitMapImageRep? If so, what are the magic parameters? If not, what is the smallest number of bits per pixel supported? You can create 1-bit NSBitMapImageReps, but you have to fill it yourself. A search in this list for "1 bit image" will give you some hints especially in the first 6 entries. -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
Sorry, pressed the wrong button. And: if the bezier path shall always be drawn 1 pixel wide, independent of resolution and scaling the lineWidth should be set to 0 (zero) -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Drawing a 1 pixel-perfect wide bordered NSBezierPath
Graham Cox wrote: Offsetting by 0.5 makes it draw such that the exact pixel is filled. When a bezier path is more complicated it can become very ugly to add 0.5 to all coordinates. To avoid this the NSBezierPath class offers the method - transformUsingAffineTransform: So you can create a bezier path "as usual" and before rendering (stroke etc.) you apply a tranformation: NSBezierPath *bezierPath = [NSBezierPath bezierPath]; NSAffineTransform *transform = [NSAffineTransform transform]; // build the bezierPath [transform translateXBy: 0.5 yBy: 0.5]; [bezierPath transformUsingAffineTransform: transform]; [bezierPath stroke]; And: if the bezier path shall always be drawn 1 pixel wide, independent -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Scaling a window background image quickly
Hi, your PDF image is a beast, its size is 624 kB and contains a lot of complicated structures. I converted the PDF into an equivalent (same size and with alpha) PNG- file with only 28 kB. But that is only important for the first drawing where an NSImage with only one representation (NSPDFImageRep) is created and rendered. For the following drawings there is not a big difference. In your code you use: [gStickyImage setCacheMode:NSImageCacheNever] ; This is deadly and makes it slow, because rendering starts from scratch, the PDF-file, not from the NSImage object. For a sharp (not pixelated) image you need to setDataRetained:YES. This is explained in the docs (NSImage -> -setDataRetained: ) and was discussed alot in this list. Using Jean-Daniel's code snippet as a starting point I tried this with success (sharp and fast): - (void)drawRect:(NSRect)aRect { if (!gSticky) { gSticky = [NSImage imageNamed:@"sticky"]; [gSticky setDataRetained:YES]; } [gSticky drawInRect:[self bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1]; } You may also set the imageInterpolation to NSImageInterpolationHigh, but only if you are not in the state of "inLiveResize" Heinrich -- Heinrich Giesen [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]