小编JWo*_*ood的帖子

将 NSButton 设为蓝色(默认)

如何在 Xcode 4 中使 NSButton 亮蓝色(即默认)?我一直在界面构建器中尝试各种选项,但似乎没有任何效果。我什至尝试设置等效于 enter 的键,这也不起作用。

任何的想法?

macos xcode cocoa objective-c

2
推荐指数
1
解决办法
1306
查看次数

STL容器泄漏

我正在使用向量容器来保存包含3个int和2个std::strings 的对象的实例,这是在堆栈上创建并从另一个类中的函数填充但是通过deleaker运行应用程序显示std::string来自对象的s都是泄露.这是代码:

// Populator function:
void PopulatorClass::populate(std::vector<MyClass>& list) {
    // m_MainList contains a list of pointers to the master objects
    for( std::vector<MyClass*>::iterator it = m_MainList.begin(); it != m_MainList.end(); it++ ) {
        list.push_back(**it);
    }
}

// Class definition
class MyClass {
private:
    std::string m_Name;
    std::string m_Description;
    int m_nType;
    int m_nCategory;
    int m_nSubCategory;
};

// Code causing the problem:
std::vector<MyClass> list;
PopulatorClass.populate(list);
Run Code Online (Sandbox Code Playgroud)

当通过deleaker运行时,泄漏的内存位于std::string类的分配器中.

我正在使用Visual Studio 2010(CRT).

string在展开堆栈并删除vector?时,我需要做些什么特别的事情才能正确删除?

谢谢,J

c++ windows winapi stl

1
推荐指数
1
解决办法
1894
查看次数

将16位色转换为32位色

我有一个16位的位图图像,每种颜色表示为一个短(2个字节),我需要在32位位图上下文中显示它.如何在C++中将2字节颜色转换为4字节颜色?

输入格式包含单个短(2个字节)中的每种颜色.

输出格式为32位RGB.这意味着我相信每个像素有3个字节?

我需要将短值转换为RGB颜色.

请原谅我缺乏色彩知识,这是我第一次进入图形编程世界.

c c++ iphone

1
推荐指数
1
解决办法
2741
查看次数

CATiledLayer、CGContextDrawImage 和 CGContextTranslateCTM

我有一个大的UIScrollView,其中包含一个CATiledLayer我用来绘制更大的图块,drawRect:如下所示:

- (void)drawRect:(CGRect)rect {
    int firstCol = floorf(CGRectGetMinX(rect) / tileSize);
    int lastCol = floorf((CGRectGetMaxX(rect)-1) / tileSize);
    int firstRow = floorf(CGRectGetMinY(rect) / tileSize);
    int lastRow = floorf((CGRectGetMaxY(rect)-1) / tileSize);

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextTranslateCTM(context, 0, tileSize);
CGContextScaleCTM(context, 1.0, -1.0);

    for( int row = firstRow; row <= lastRow; row++ ) {
    for( int col = firstCol; col <= lastCol; col++ ) {
            UIImage = [self getTileWithRow:row column:col];

            CGRect tileRect = CGRectMake((col * tileSize), 
                                         row * …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c quartz-graphics quartz-2d

1
推荐指数
1
解决办法
2153
查看次数

核心图形绘制线与轮廓

我正在使用Core Graphics绘制一条宽度为4像素的任意线,现在我希望这条线具有另一种颜色的1像素轮廓.我看不到任何能够实现这种"开箱即用"的CG功能,但我正在寻找有关如何实现这一目标的建议.这是我现有的代码:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);

CGPoint curPoint = [(NSValue*)[points objectAtIndex:0] CGPointValue];
CGContextMoveToPoint(context, curPoint.x, curPoint.y);

for( int i = 1; i < [points count]; i++ ) {
    curPoint = [(NSValue*)[points objectAtIndex:i] CGPointValue];
    CGContextAddLineToPoint(context, curPoint.x, curPoint.y);
    CGContextStrokePath(context);
    CGContextMoveToPoint(context, curPoint.x, curPoint.y);
}
Run Code Online (Sandbox Code Playgroud)

这会产生单线.我想生产一条4px线,1px线突出显示4px线,如下所示:

http://img692.imageshack.us/img692/6196/lineexample.png

iphone cocoa-touch core-graphics

1
推荐指数
1
解决办法
1979
查看次数