CocoaGurus
September 09, 2010, 10:59:42 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Bienvenido a CocoaGurus
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Pasar un buffer a un NSImage  (Read 743 times)
xphere
Newbie
*
Posts: 7



View Profile WWW
« on: April 25, 2009, 02:00:21 PM »

Hola a todos!!!

Antes de todo, felicidades por los seminarios de ayer (yo estaba en el sofá del fondo Tongue).

Después... la pregunta!

Estoy pasando un programa que tengo de Win a Mac, el programa tiene un "core" hecho en C++ que mantengo por temas de portabilidad (es decir, usa solo libs estandard y no puedo usar nada de objectiveC, ni de las libs de mac).
El tema es que tengo un buffer con una imagen, y la he de pasar a una estructura de datos NSImage.
El buffer es un puntero a un array de 'chars' de longitud Width*Heigh*bpp, por ejemplo para una imagen de 128x128 de tipo RGB, sería de 128x128x3 = 49152 bytes

He probado con lo siguiente (sin éxito), me hago un follón con lo de 'isPlanar', ya que no se muy bien para que sirve... de momento, mi code peta:
Code:
NSBitmapImageRep* imageRep;
imageRep=[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&tg_temptext[0]->t.data
  pixelsWide:tg_temptext[0]->t.w
  pixelsHigh:tg_temptext[0]->t.h
   bitsPerSample:8
samplesPerPixel:tg_temptext[0]->t.iformat
hasAlpha:NO
isPlanar:NO
  colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:(tg_temptext[0]->t.w*tg_temptext[0]->t.iformat)
bitsPerPixel:0] autorelease];


NSImage* sourceImage = [[[NSImage alloc] initWithSize:NSMakeSize(tg_temptext[0]->t.w, tg_temptext[0]->t.h)] autorelease];
[sourceImage addRepresentation:imageRep];

if ([sourceImage isValid])
{
NSImage* thumbnail = sourceImage;
(...)

Alguna sugerencia??
« Last Edit: April 25, 2009, 02:14:24 PM by xphere » Logged

zon@n power!
xphere
Newbie
*
Posts: 7



View Profile WWW
« Reply #1 on: April 26, 2009, 04:33:13 AM »

Pues ya lo he encontrado!!

El código correcto queda asi:
Code:
NSBitmapImageRep* imageRep;
imageRep=[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **)&tg_temptext[0]->t.data
  pixelsWide:tg_temptext[0]->t.w
  pixelsHigh:tg_temptext[0]->t.h
   bitsPerSample:8
samplesPerPixel:tg_temptext[0]->t.iformat
hasAlpha:NO
isPlanar:NO
  colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:(tg_temptext[0]->t.w*tg_temptext[0]->t.iformat)
bitsPerPixel:(tg_temptext[0]->t.iformat*8)] autorelease];


NSImage* sourceImage = [[[NSImage alloc] initWithSize:NSMakeSize(tg_temptext[0]->t.w, tg_temptext[0]->t.h)] autorelease];
[sourceImage addRepresentation:imageRep];

sigo sin entender porque hay que poner "isPlanar:NO", pero lo cierto es que solo asi me funciona... :S
Logged

zon@n power!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!