If you named them width and height, you wouldn't have to add notes like that
for other people reading your code.
On Sep 26, 2011, at 1:46 PM, koko wrote:
> I alos forgot to say that x and y below are pixels x and pixels y of the
> bitmap, i.e. its size.
>
> On Sep 26, 2011, at 12:28 PM, koko wrote:
>
>> I too am working in a cross platform environment and use bitmaps in an
>> NSView. I use the code below and it is fast enough to pan , scroll etc with
>> no sense of sluggishness.
>> My code looks a little different than what you have submitted. You might
>> re-factor to my model.
>>
>>
>> CGColorSpaceRef colorSpace;
>> colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
>> provider;
>> CGImageRef bitmap;
>>
>> provider = CGDataProviderCreateWithData (NULL,m_main.m_bitmap.m_array,
>> 4*x*y, NULL);
>> bitmap = CGImageCreate(x, y, 8, 32, 4*x, colorSpace,
>> kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Host,provider, NULL,true,
>> kCGRenderingIntentDefault);
>>
>> CGRect r;
>> if(bitmap)
>> {
>> NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
>> CGContextRef context = (CGContextRef)[graphicsContext graphicsPort];
>> r = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width,
>> rect.size.height);
>> CGContextDrawImage(context, r, bitmap);
>> }
>>
>> CGColorSpaceRelease(colorSpace);
>> CGDataProviderRelease(provider);
>> CGImageRelease(bitmap);
>>
>> On Sep 24, 2011, at 12:30 PM, Vojtěch Meluzín wrote:
>>
>>> Hi folks,
>>>
>>> I'm implementing a crossplatform (not-only GUI) library, where everything is
>>> drawn internally to an RGBA bitmap and then just copied to screen. On
>>> Windows it works like charm especially since there is a support for
>>> "in-memory" bitmaps. But I don't see such a feature on Mac. I ended up with
>>> this code:
>>>
>>> CGColorSpaceRef colorSpace =
>>> CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
>>> CGContextRef bmpcontext =
>>> CGBitmapContextCreate((void*)desc.Bitmap.GetData(),
>>> sz.X, sz.Y, 8, sz.X
>>> * 4, colorSpace, kCGImageAlphaNoneSkipLast);
>>> CGColorSpaceRelease(colorSpace);
>>>
>>> CGContextSaveGState(context);
>>> CGRect cliprect = { r.X1, sz.Y - r.Y2, r.GetWidth(), r.GetHeight()
>>> };
>>> CGContextClipToRect (context, cliprect);
>>> CGContextSetShouldAntialias (context, false);
>>>
>>> HIRect bounds;
>>> bounds.origin.x = 0;
>>> bounds.origin.y = 0;
>>> bounds.size.width = sz.X;
>>> bounds.size.height = sz.Y;
>>>
>>> CGImageRef temp = CGBitmapContextCreateImage (bmpcontext);
>>> CGContextDrawImage(context, bounds, temp);
>>>
>>> CGImageRelease(temp);
>>> CGContextRelease (bmpcontext);
>>>
>>> CGContextRestoreGState (context);
>>>
>>>
>>> It basically converts the whole bitmap into CGImageRef and then copies a
>>> part of it into the NSView's context. But it's quite slow. Is there a better
>>> way to do this? And is there a way to create the in-memory images like they
>>> are on Windows?
>>>
>>> One more thing - I do the same thing in Carbon (I just need Cocoa because of
>>> x64...) and I noticed that the coordinates for the CGContext is inverted
>>> vertically, is that correct?? I mean the same context object type, but
>>> different Y handling...
>>>
>>> Thanks in advance.
>>> Vojtech
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list ([email protected])
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net
>>>
>>> This email sent to [email protected]
>>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list ([email protected])
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net
>>
>> This email sent to [email protected]
>>
>
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/lrucker%40vmware.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]