• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing NSImage resolution - or display it at pixel size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing NSImage resolution - or display it at pixel size


  • Subject: Re: Changing NSImage resolution - or display it at pixel size
  • From: Jeremy Dronfield <email@hidden>
  • Date: Tue, 4 May 2004 13:20:48 +0100

Thanks, but the article doesn't really help. Manipulating the pixel size of the image rep doesn't work - at least it doesn't work within a text view. With the pixel size recalculated according to the ratio of original pixel size to original image size, the result is a totally screwed rendering, with the colour channels split and the image (in its original size) appearing in the corner of a big black rectangle. The code I originally posted - which sets the size of the image and the rep to the pixel size of the rep - does work. The image displays at its pixel size. The problem is that it reverts to its original size after the file is saved and reopened.

If anything, the article merely confirms that the problem is actually with the way NSTextAttachment handles images. Presumably, the only way around this problem is to copy the image, change its size, write that image to file, then recreate the attachment with a wrapper based on the new file.

Regards,
-Jeremy

On 4 May 2004, at 7:54 am, p3consulting wrote:

See

http://www.macosxguru.net/article.php?story=20031209091834195

Pascal Pochet
email@hidden
----------------------------------
PGP
KeyID: 0x208C5DBF
Fingerprint: 9BFB 245C 5BFE 7F1D 64B7 C473 ABB3 4E83 208C 5DBF


Le mai 3, 2004, ` 22:39, Jeremy Dronfield a icrit :

I've been struggling with this problem for two days, and haven't found anything in the archives to solve it. How do you change the resolution of an NSImage? And if that isn't possible (it must be), is there a way to force an NSTextView to display images in attachments at their pixel size instead of dpi?

Below is the code I'm using to (try to) change the resolution of a jpg image (200 dpi) containing one NSBitmapImageRep in an NSTextAttachmentCell:

if ([(NSCell *)[imAttachment attachmentCell] respondsToSelector:@selector(image)]) {

NSImage *theImage = [[(NSCell *)[imAttachment attachmentCell] image] copy];

NSLog(@"initial image:%@", [theImage description]);

NSBitmapImageRep *rep = [[theImage representations] objectAtIndex:0];
int renderedWidth = [rep pixelsWide];
int renderedHeight = [rep pixelsHigh];

[rep setSize:NSMakeSize(renderedWidth, renderedHeight)];
[theImage setSize:NSMakeSize(renderedWidth, renderedHeight)];

[theImage addRepresentation:rep];
[theImage removeRepresentation:[[theImage representations] objectAtIndex:0]];

if ([(NSCell *)[imAttachment attachmentCell] respondsToSelector:@selector(setImage:)])
[(NSCell *)[imAttachment attachmentCell] setImage:theImage];

NSLog(@"adjusted image:%@", [theImage description]);

[theImage release];
}

At first, this appears to work. The image in the text appears at its pixel size. This is borne out by the log output:

initial image:NSImage 0x3e8c10 Size={130.32, 94} Reps=(
NSBitmapImageRep 0x3e8c30 Size={130.32, 94} ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=362x261 Alpha=NO

adjusted image:NSImage 0x3e8c10 Size={362, 261} Reps=(
NSBitmapImageRep 0x3e8c30 Size={362, 261} ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=362x261 Alpha=NO

However, when the text view's contents are saved to RTFD and reloaded later, the image has slipped back to its original size. Why does this happen? Is there a better way to change the image's resolution? Or preferably, is there a way simply to get NSTextView to show images at their pixel size regardless of dpi?

Regards
-Jeremy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Changing NSImage resolution - or display it at pixel size (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: CAWUG - mea culpa
  • Next by Date: ANN:a long desired feature comes into OCSmart Hacks
  • Previous by thread: Changing NSImage resolution - or display it at pixel size
  • Next by thread: NSOpenPanel Oddity
  • Index(es):
    • Date
    • Thread