objective c - NSBitmapImageRep -initWithFocusedViewRect is doubling size of image -
i have following objective-c function meant resize nsbitmapimagerep designated size.
currently, when working image of size 2048x1536 , trying resize 300x225, function keeps returning nsbitmapimagerep of size 600x450.
- (nsbitmapimagerep*) resizeimagerep: (nsbitmapimagerep*) anoriginalimagerep totargetsize: (nssize) atargetsize { nsimage* thetempimagerep = [[[nsimage alloc] initwithsize: atargetsize ] autorelease]; [ thetempimagerep lockfocus ]; [nsgraphicscontext currentcontext].imageinterpolation = nsimageinterpolationhigh; nsrect thetargetrect = nsmakerect(0.0, 0.0, atargetsize.width, atargetsize.height); [ anoriginalimagerep drawinrect: thetargetrect]; nsbitmapimagerep* theresizedimagerep = [[[nsbitmapimagerep alloc] initwithfocusedviewrect: thetargetrect ] autorelease]; [ thetempimagerep unlockfocus]; return theresizedimagerep; } debugging it, i'm finding thetargetrect of proper size, call initwithfocusedrec returns bitmap of 600x450 pixels (high x wide)
i'm @ complete loss why may happening. have insight?
your technique won't produce resized image. 1 thing, method initwithfocusedviewrect:reads bitmap data focused window , used create screen grabs.
you should create new graphics context new nsbitmapimagerep or nsimage of desired size draw image context.
something this.
nsgraphicscontext* context = [nsgraphicscontext graphicscontextwithbitmapimagerep:thetempimagerep]; if (context) { [nsgraphicscontext savegraphicsstate]; [nsgraphicscontext setcurrentcontext:context]; [anoriginalimagerep drawatpoint:nszeropoint]; [anoriginalimagerep drawinrect:thetargetrect]; [nsgraphicscontext restoregraphicsstate]; } // temp image rep should have resized original.
Comments
Post a Comment