Re: Resizing an image inside a text view
Re: Resizing an image inside a text view
- Subject: Re: Resizing an image inside a text view
- From: email@hidden (Heinrich Giesen)
- Date: Mon, 29 Nov 2004 17:59:02 +0100
Hello,
// My initial test code to resize an image within the text view
snip
[self imageResize:image
newSize:NSMakeSize(200.0,200.0)]; // A random test
Don't use this method ! It is time consuming, space consuming
and worse: it destroys irreversibly the pixel structure of the
image. Do you really want to resize the image
(better: the imageReps) ? I'm sure you don't. You only want to
resize the appearance of the image. Try the above method to
shrink your image and then resize it to the original size. The
quality is bad! You need a lossless resize method:
For your testcase it is good enought to write:
NSImage *image = [cell image]; // in resizeImage:
[image setSize: NSMakeSize(200.0,200.0)];
That will do it.
1) The changes to the image aren't visible until you
Insert after scaling:
[layoutManager textContainerChangedGeometry: textContainer];
2) If I drag the image out of the text view and then
drop it back in, the image returns to its original
size.
Yes, it also uses the original size when copying the textView.
This is because for these operations the data from the
attachments fileWrapper is used.
And these data are still not changed. Create a new fileWrapper
with the scaled imageReps (not the scaled image!) and replace
the attachment.
BTW in my testApp it only works for NSBitmapImageReps not for other reps.
There must be another way to scale images in a textView.
Heinrich Giesen
--
Heinrich Giesen
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden