I need to resize NSImage in NSTextView. And i did it, but when i try change place of image (my NSImage) in the NSTextView - then my Image gets it's old size. Can someone help to me? Here is code, that i use:
- (void)textView:(NSTextView *)textView doubleClickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame atIndex:(NSUInteger)charIndex {
NSImage * image = [(NSCell *)cell image];
NSSize imageSize = [image size];
self.resizeImageController.sizeBefore = imageSize;
self.resizeImageController.imageForResize = image;
self.resizeImageController.textViewWithImage = textView;
self.resizeImageController.textAttachmentCell = cell;
[[self.resizeImageController window]orderFront:self];
}
It was delegate's of NSTextView method, and than i resize Imge in resizeImageController in method - (void)resizeImage; :
- (void)resizeImage {
NSSize newSize = ...;//Get new image size - the dimensions are correct, the error is not exactly here
[self.imageForResize setSize:newSize];
NSImage *newImage = [[[NSImage alloc] initWithSize:newSize] autorelease];
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc]
initWithData:[self.imageForResize TIFFRepresentation]] autorelease];
[rep setSize:newSize];
[newImage addRepresentation:rep];
[self.textAttachmentCell setImage:newImage];
self.imageForResize = newImage;
[[self.textViewWithImage layoutManager] textContainerChangedGeometry: [self.textViewWithImage textContainer]];
}