您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > ProgrammingWithCocoa(24)位图
ProgrammingWithCocoa(24)CocoaCocoaNSImageRepNSBitmapImageRepTIFFGIFJPEGPNGBMPImageAppNSImageNSImageImageAppNSBitmapImageRepImageApp“Filter”“MakeGrayscale”MyDocument“MakeGrayscale”MainMenu.nibFirstResponderMyDocumentFile'sOwnerFirstRespondernibFirstRespongerFirstResponderFile'sOwnerIBMainMenu.nibFirstResponderFirstRespondermakeGrayscale:Cocoa-MenuSubmenuEditWindowFilterItem“MakeGrayscale”FirstRespondermakeGrayscale:IBPBProjectBuilderImageAppMyDocumentmakeGrayscale:IAGrayscaleFilter-filterImage:NSImageNSImageretainMyDocumentactiveImageIAWindowController-setImageToDraw:-makeGrayscale:MyDocument.m-(void)makeGrayscale:(id)sender{IAGrayscaleFilter*filter=[[IAGrayscaleFilteralloc]init];[activeImageautorelease];activeImage=[[filterfilterImage:activeImage]retain];[windowControllersetImageToDraw:activeImage];[filterrelease];}IAGrayscaleFilterMyDocumentIAGrayscaleFilteractiveImageautoreleaseactiveImageNSImagewindowControllerIAWindowController-setImageToDraw:-(void)setImageToDraw:(NSImage*)image{[viewsetImage:image];}setImage:IAGrayscaleFilter-(NSImage*)filterImage:(NSImage*)srcImage;#importAppKit/AppKit.hfilterImage:NSImageNSImageNSImageNSImageNSBitmapImageRepImageAppNSImageNSImageRepNSImageNSImageRepNSImageNSImageRep-(NSImage*)filterImage:(NSImage*)srcImage{NSBitmapImageRep*srcImageRep=srcImageRep=[NSBitmapImageRepimageRepWithData:[srcImageTIFFRepresentation]];...}NSBitmapImageRepimageRepWithData:TIFFNSDataTIFFNSImageTIFFRepresentationNSImageNSImageNSImageNSBitmapImageRepӐӐ125ӐCocoaӐfilterImage:-(NSImage*)filterImage:(NSImage*)srcImage{NSBitmapImageRep*srcImageRep=[NSBitmapImageRepimageRepWithData:[srcImageTIFFRepresentation]];intw=[srcImageReppixelsWide];inth=[srcImageReppixelsHigh];intx,y;NSImage*destImage=[[NSImagealloc]initWithSize:NSMakeSize(w,h)];NSBitmapImageRep*destImageRep=[[[NSBitmapImageRepalloc]initWithBitmapDataPlanes:NULLpixelsWide:wpixelsHigh:hbitsPerSample:8samplesPerPixel:1hasAlpha:NOisPlanar:NOcolorSpaceName:NSCalibratedWhiteColorSpacebytesPerRow:NULLbitsPerPixel:NULL]autorelease];...[destImageaddRepresentation:destImageRep];return[destImageautorelease];}destImageNSImageNSImagedestImageRepdestImagedestImageRepdestImageaddRepresentation:NSBitmapImageRepBitmapDataPlanes:alphaNSBitmapImageRepRGBunsignedchar**NULLpixelsHigh:pixelsWide:bitsPerSample:8-bits12-16-bitssamplesPerPixel:RGB31alphaalphaNONOColorspaceRGBRGB——CocoaNSCalibratedWhiteColorSpaceNULLbytesPerRowpixelsWide*bitsPerSample*samplesPerPixel/8bitsPerPixel:bitsPerSample*samplesPerPixelNSBitmapImageRepCCxyfor(y=0;yh;y++){for(x=0;xw;x++){//!}}srcImageRepdestImageRepbitmapDatabitmapDataunsignedchar*unsignedchar8-(NSImage*)filterImage:(NSImage*)srcImage{NSBitmapImageRep*srcImageRep=[NSBitmapImageRepimageRepWithData:[srcImageTIFFRepresentation]];NSImage*destImage=[[NSImagealloc]initWithSize:NSMakeSize(w,h)];intw=[srcImageReppixelsWide];inth=[srcImageReppixelsHigh];intx,y;NSBitmapImageRep*destImageRep=[[[NSBitmapImageRepalloc]initWithBitmapDataPlanes:NULLpixelsWide:wpixelsHigh:hbitsPerSample:8samplesPerPixel:1hasAlpha:NOisPlanar:NOcolorSpaceName:NSCalibratedWhiteColorSpacebytesPerRow:NULLbitsPerPixel:NULL]autorelease];unsignedchar*srcData=[srcImageRepbitmapData];unsignedchar*destData=[destImageRepbitmapData];unsignedchar*p1,*p2;for(y=0;yh;y++){for(x=0;xw;x++){}}[destImageaddRepresentation:destImageRep];return[destImageautorelease];}srcDatadestDatap1p2248-bitsalphayxyxxyCCsrcData*srcDatasrcDataяsrcDatasrcDataяsrcData+1яsrcData+2*(srcData+1)я*srcData+1unsignedchar*srcData=[srcImageRepbitmapData];unsignedchar*destData=[destImageRepbitmapData];unsignedchar*p1,*p2;intn=[srcImageRepbitsPerPixel]/8;for(y=0;yh;y++){for(x=0;xw;x++){p1=srcData+n*(y*w+x);p2=destData+y*w+x;*p2=(unsignedchar)rint((*p1+*(p1+1)+*(p1+2))/3);}}forp1yxyxnn3srcDatap2NSCalibratedWhiteColorspacen1p1p1p1*p1p1+1p1+2*p1*(p1+1)*(p1+2)unsignedchar8-bitsp2*p2CC*(p1+n)p1np1[n]unsignedchar*srcData=[srcImageRepbitmapData];unsignedchar*destData=[destImageRepbitmapData];unsignedchar*p1,*p2;intn=[srcImageRepbitsPerPixel]/8;for(y=0;yheight;y++){for(x=0;xwidth;x++){p1=srcData+n*(y*w+x);p2=destData+y*w+x;p2[0]=(unsignedchar)rint((p1[0]+p1[1]+p1[2])/3);}}forn*y*wunsignedchar*srcData=[srcImageRepbitmapData];unsignedchar*destData=[destImageRepbitmapData];unsignedchar*p1,*p2;intn=[srcImageRepbitsPerPixel]/8;intsrcBPR=[srcImageRepbytesPerRow];intdestBPR=[destImageRepbytesPerRow];for(y=0;yheight;y++){for(x=0;xwidth;x++){p1=srcData+y*srcBPR+n*x;p2=destData+y*destBPR+x;p2[0]=(unsignedchar)rint((p1[0]+p1[1]+p1[2])/3);}}-filterImage:-(NSImage*)filterImage:(NSImage*)srcImage{NSBitmapImageRep*srcImageRep=[NSBitmapImageRepimageRepWithData:[srcImageTIFFRepresentation]];NSImage*destImage=[[NSImagealloc]initWithSize:NSMakeSize(w,h)];intw=[srcImageReppixelsWide];inth=[srcImageReppixelsHigh];intx,y;NSBitmapImageRep*destImageRep=[[[NSBitmapImageRepalloc]initWithBitmapDataPlanes:NULLpixelsWide:wpixelsHigh:hbitsPerSample:8samplesPerPixel:1hasAlpha:NOisPlanar:NOcolorSpaceName:NSCalibratedWhiteColorSpacebytesPer
本文标题:ProgrammingWithCocoa(24)位图
链接地址:https://www.777doc.com/doc-12096 .html