I'm trying to change the desktop image; The process that I came up with is below, for the first time, this code is run, again the shape image is displayed on the screen as a screen, but the next time there is no response. What am i doing
- (IBAction) click: (ID) sender {NSData * sourceData; NSError * error; NSFileManager * filemgr; Filemgr = [NSFileManager default manager]; Screen array = [NSScreen screen]; Screen count = [screen array count]; Unsigned index = 0; For {index; index and lieutenant; screen count; index ++} {screen = [screen ARRA ObjectAutlook: index]; ScreenTrack = [screenviewframe]; } NSLog (@ "% fx% f", screen-size. Size.width, screenRect.size.height); ArrCatDetails = [StrCatDetails Components with Authorized Bastring: appDelegate.strColDelimiter]; NSString * imageURL = [NSString stringWithFormat: @ "Upload / Product / Image /% @ _% @ _% d.jpg", [arrCatDetails ObjectIntextX: 0], App Delegate .str104by157Name, iSelectedImgIndex]; NSString * ima = [imageURL Last Text Company]; NSString * str = [NSHome directory (stringByAppendingPathComponent: @ "document"]; NSString * DataFilePath = [StringBappingPath Company: IMA]; NSString * imagePath = [NSString stringWithFormat: @ "file: // localhost% @", data-path]; NSDRAEL * URL = [[NSUR AL Alok] Init]; Url = [NSURL URLWithString: imagePath]; SourceData = [NSData Datatyh content of URL: URL]; Source image = [[NSImage alloc] initWithData: sourceData]; ResizedImage = [[NSImage alloc] initWithSize: NSMakeSize (screenRect.size.width, screenRect.size.height)]; Original Size NSSize = [sourceImage size]; [Resized image lock focus]; [SourceImage drawInRect: NSMakeRect (0, 0, screenRect.size.width, screenRect.size.height) Direct: NSMKACT (0, 0, original size width, original size.) Operation: NSCMopociSourceOperation Excerpt: 1.0]; [Resize Image Unlock Focus]; NSDTA * resized data = [resized image TIFF Representation]; NSBitmapImageRep * theImageRepresentation = [NSBitmapImageRep imageRepWithData: resizedData]; Newimage = @ "editwall.jpg"; NewFilePath = [StringBappingPathConcent: NewMeG]; NSDTA *ImageData = [image reflection rendering typing: NSJPEGFFileType property: zero]; [Imagedata instrument file: newfile path atom: yes]; If ([filemgr filexstap: newFilePath] == yes) {imagePath1 = [NSString stringWithFormat: @ "file: // localhost% @", new file path]; Urlz = [NSURL URLWithString: imagePath1]; NSDictionary * option = [Objects with NSDictionary dictionary: Ends: Nil, NS Works SpaceDeskTextEffectCollectorKe, [NSNumber NumberWithblue: NO], NS Works SpaceDesktopEmolveClifingKe, [NSMM ScalePrprPresselEver Down with NSM Number Number], NSI Works SpaceDesktop Issues Scaleing; [[NSWorkspace sharedWorkspace] setDesktopImageURL: urlz forScreen: [[NSScreen screen] Final object] Option: Option error: & amp; Error]; } And {nslog (@ "no"); } [SourceImage release]; [Resized image release]; }
Why not try? There is a sample project in the apple that you are asked to give some ideas about using it.
Edit (After your code is read more carefully): You may have problems due to your call + [NSDictionary dictionaryWithObjectsAndKeys:] See zero at the end of the list of arguments? Similarly, you tell NSDictionary that your logic is not listed, you can not put zero in the list, as that list will stop reading at that time. If you want to specify a value that does not have a value, then you have to use [NSNull null] .
On the one hand: you get a memory management problem: Your code: // for a NSURL NSURL * url = [[NSURL alloc] init] Allocates memory; // allocates more memory for an NSURL, and leak / first allocation url = [NSURL URLWithString: imagePath]; Just make one or the other:
// If you do this, you will need to call the NS URL [/ url release] later * Url = [[NSRL Alok] initWithString: imagePath]; // This memory will be automatically issued by NSURL * otherUrl = [NSURL URLWithString: imagePath];
Comments
Post a Comment