Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / September 2007



Tip: Looking for answers? Try searching our database.

NSImage to JPG Batch problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zon7 - 21 Sep 2007 13:23 GMT
HI, I've been trying to do a batch converter for images. The problem
is the memory is not being released properly. When the for ends the
memory is ok, but during the for it continues increasing. I have a
function with a for loop:
    for(count=0;count<cant;count++)
    {
        path=[datos objectAtIndex:count];
        save_name=[NSString stringWithFormat:
                @"image_%04d.jpg",count+1];
        output=[[batch_outdir stringValue]
stringByAppendingPathComponent:save_name];
        [self convert:path path_out:output format:NSJPEGFileType quality:
0.3];
    }

and then the conversion function

-(void)convert:(NSString*)path_in path_out:(NSString*)path_out format:
(NSBitmapImageFileType)type quality:(float)q
{
    NSDictionary *d=[NSDictionary dictionaryWithObject:
                        [NSNumber numberWithFloat:q]
                        forKey:NSImageCompressionFactor];
    NSImage    *tmp_img;
    NSBitmapImageRep *b;
    NSData *data;

    tmp_img=[[NSImage alloc] initWithContentsOfFile:path_in];
    b=[NSBitmapImageRep imageRepWithData:[tmp_img TIFFRepresentation]];
    [tmp_img release];

    data=[b representationUsingType:tipo properties:d];
    [data writeToFile:path_out atomically:TRUE];
}
David Phillip Oster - 21 Sep 2007 16:12 GMT
> HI, I've been trying to do a batch converter for images. The problem
> is the memory is not being released properly. When the for ends the
> memory is ok, but during the for it continues increasing. I have a
> function with a for loop:
>     for(count=0;count<cant;count++)
>     {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>         path=[datos objectAtIndex:count];
>         save_name=[NSString stringWithFormat:
[quoted text clipped - 3 lines]
>         [self convert:path path_out:output format:NSJPEGFileType quality:
> 0.3];
[pool release];
>     }
Michael Ash - 21 Sep 2007 16:15 GMT
> HI, I've been trying to do a batch converter for images. The problem
> is the memory is not being released properly. When the for ends the
> memory is ok, but during the for it continues increasing. I have a
> function with a for loop:

Please learn to crosspost:

http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

The way you posted now, I saw your message twice, and had to mark it as
read twice. Crossposting correctly will make it so I only see it once. Of
course the best way is to only post to a single group. This question is
off-topic for comp.lang.objective-c anyway, so it doesn't really belong
there.

Signature

Michael Ash
Rogue Amoeba Software

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.