나는 간단한 Obj C 프로그램을 사용하여 이미지를로드하고 이론적으로 그 이미지를 확대하고 회전 할 수있게해야합니다. NSAffineTranslations를 사용하고 있습니다.NSView에서 이미지 그리기
왼쪽 위의 PS/PDF 표준과 반대로 이미지가 왼쪽 상단에 잠겨 있으므로 isFlipped를 사용하고 [afTrans scaleXBy : 1.0 yBy : -1.0]을 호출합니다.
문제는 어떤 이유로 든 내 drawRect가 처음 호출 된 후 변형이 발생하지 않는다는 것입니다.
나는 이미지를로드
, 그것은 등장하고, 올바른 보인다. 창의 크기 (drawRect를 호출하는)를 변경하면 이미지가 그려 지지만 거꾸로 뒤집혀 반전됩니다. 이것은 변형이 효과가 없다는 것을 의미합니다. 두 번째 시간에는 어떤 데이터에도 차이가 보이지 않습니다.- (void)drawRect:(NSRect)rect
{
// Drawing code here.
// NSLog(@"window type: %d", [[self window] backingType]);
NSAffineTransform *afTrans = [[NSAffineTransform alloc] init];
NSGraphicsContext *context = [NSGraphicsContext currentContext];
NSSize sz;
NSRect windowFrame = [[self window] frame];
NSRect cv =[[[self window] contentView] frame];
float deltaX, deltaY;
NSSize superSize = [[self superview] frame].size;
float height, width, sHeight, sWidth;
NSRect imageRect;
sz = [ image size];
imageRect.size = sz;
imageRect.origin = NSZeroPoint;
height = sz.height ;
width = sz.width ;
// sHeight and sWidth are the hieght and with of the super-view. ie,
// the size of the whole window view including the space for the
// scroll bars, etc, but not including the panel or the borders,
sHeight = superSize.height;
sWidth = superSize.width;
[context saveGraphicsState];
deltaX = 0;
deltaY = 0;
deltaY += height; // account for flipping
[afTrans translateXBy:deltaX yBy:deltaY];
[afTrans scaleXBy:1.0 yBy:-1.0];
[afTrans concat];
NSRect drawingRect = imageRect;
NSRect frame = imageRect;
[self setFrame:frame];
[image drawInRect:drawingRect
fromRect:imageRect
operation:NSCompositeSourceOver
fraction:1];
[afTrans release];
[context restoreGraphicsState];
}
ETA는 : 여기에 관련이있을 수있는 몇 가지 더 많은 코드의 여기
코드의 버전을 박탈입니다.-(void)setImage:(NSImage *)newImage
{
[newImage retain];
[image release];
rotation = 0;
zoom = 1.0;
image = newImage;
NSSize imageSize = [newImage size];
NSRect tFrame = [self frame];
tFrame = [[self window] frame];
tFrame.size.width = MAX(tFrame.size.width, imageSize.width);
tFrame.size.height = MAX(tFrame.size.height, imageSize.height);
[self setFrame:tFrame];
[self setNeedsDisplay:YES];
}
[crickets] 나는 이미 tumbleweed 배지를 가지고 있습니다.이 질문이 애매한 경우 B-) –