AppleScriptObjC中的NSImage release() [英] NSImage release() in AppleScriptObjC
问题描述
我正在创建一个表格视图,每行显示小图像。 数据源
为表的每一行保存一个图像。我通过将 img设置为NSImage()的alloc()的initWithContentsOfFile_(thePath)
创建图像。接下来,通过将imageView的图像设置为img
,以较大的浏览器视图显示选定行的图像。问题是我的内存不足,因为我对两个视图使用相同的表示形式。 (图像约为500x400)。
我试图找出如何从较大的版本制作较小的版本,然后发布较大的图像。
I'm creating a Table View with small images displayed in each row. The data source
holds an image for each row of an table. I create images thru set img to NSImage()'s alloc()'s initWithContentsOfFile_(thePath)
. Next I display the image of selected row in bigger, browser view thru set imageView's image to img
. Problem is that I'm running out of memory because I use the same representation for both views. (Images are around 500x400).
I'm trying to figure out how to make a smaller version from bigger one and then release a bigger image.
我从发布图像开始。.
我尝试了 img的release()
,但没有工作了。除了垃圾回收,ARC和内存管理,我找不到有关该主题的任何信息。一个>。我已经在 XCode
中启用了 Objective-C自动引用计数
,但可能不适用于Applescript部分一个交易。有没有办法在纯ApplescriptObjC中实现它?
I started from releasing an image..
I have tried img's release()
but it not worked. I couldn't find any info on that topic besides Garbage Collection, ARC, and managing memory. I have turned-on Objective-C Automatic Reference Counting
in XCode
but probably it doesn't applies to Applescript part of a deal. Is there an way to achieve it in pure ApplescriptObjC?
推荐答案
尝试以下代码(调整变量名和UI控件属性):
Try this code (adjusting for your variable names and UI control properties):
set curImage to current application's NSImage's alloc()'s initWithContentsOfFile:thePath
-- create a smaller image
set newImage to current application's NSImage's alloc()'s initWithSize:{48, 48}
newImage's lockFocus()
curImage's drawInRect:{{0,0}, {48, 48}} fromRect:{{0,0},{0,0}} operation:2 fraction:1.0
newImage's unlockFocus()
imgArtwork's setImage:newImage
set curImage to missing value -- release large image
这篇关于AppleScriptObjC中的NSImage release()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!