hi whenever i am running this through the command line, my app is crashing with the error "GraphicsConetext not init" my code crashes at the call of [lock focus]i am not creating any view till now So can i do it without lock/unlock focus and without view and if not then is it possible to create a hidden view from command line so the user wont get any wind that the view was called ..
Advanced Thanx ppl -Parimal On Fri, Jan 9, 2009 at 10:25 PM, Steve Christensen <puns...@mac.com> wrote: > For a bitmap image, -setSize: effectively alters the DPI of the pixels but > doesn't actually create a new bitmap of a different size. So for a 72dpi > image, the NSBitmapImageRep's -width and -height methods should give you the > same values as for the image's -size method. But for a 300dpi image, for > example, you'd expect the -width and -height values to be about 4x larger > than the -size value. > > Maybe something like this would do what you want? > > NSImage* originalIcon = [[NSWorkspace sharedWorkspace] > iconForFile:filePath]; > NSRect resizedBounds = NSMakeRect(0, 0, 384, 384); > NSImage* resizedIcon = [[[NSImage alloc] resizedBounds.size] autorelease]; > > [resizedIcon lockFocus]; > [originalIcon drawInRect:resizedBounds fromRect:NSZeroRect > operation:NSCompositeCopy fraction:1.0]; > [resizedIcon unlockFocus]; > > NSBitmapImageRep* bitmapImage = [[resizedIcon representations] > objectAtIndex:0]; > [[bitmapImage representationUsingType:NSJPEGFileType properties:dict] > writeToFile:destPath atomically:YES]; > > Probably safer to iterate the representation(s) and actually add a check to > see that bitmapImage really is one before actually using it, just in case > another representation is created. > > steve > > > > On Jan 9, 2009, at 5:50 AM, Parimal Das wrote: > > hi >> in my application i need to resize a .jpg image through a command line >> >> my code is >> >> NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:filePath]; // >> get >> icon from the file at filePath destination >> >> NSSize imageSize; >> >> imageSize.width = 384.0; // in points (384 pts = 512 px ) >> >> imageSize.height = 384.0; >> >> >> [icon setSize:imageSize]; // set image size >> >> >> NSData * tiffData = [icon TIFFRepresentation]; >> >> bitmapImageRep = [NSBitmapImageRep imageRepWithData:tiffData]; >> >> [[bitmapImageRep representationUsingType:NSJPEGFileType properties:dict] >> writeToFile:destPath atomically:YES]; // write it to a file path stored in >> destPath >> >> >> this code is not altering the size at all >> >> i cant create a NSView as its a command line app >> >> any suggestions ??? how to resize it?? >> > > -- -- Warm Regards, Parimal Das _______________________________________________ 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