Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

drawing NSImage in a NSCustomView

 
   Macintosh computer (Home) -> General Discussion RSS
Next:  java app  
Author Message
webstuff

External


Since: Feb 27, 2004
Posts: 82



(Msg. 1) Posted: Sat Mar 20, 2004 3:46 am
Post subject: drawing NSImage in a NSCustomView
Archived from groups: comp>sys>mac>programmer>misc (more info?)

Im a newb with ObjC and Cocoa. I have been able to load an jpg from a
resource bundle and setImage: in a NSImageView. That works perfectly.

Now I know that I can load the image correctly. I am trying to draw the
nsimage onto a subclassed NSView. I have subclassedd a NSView, and in the
initWithFrame: method, I load the image into a NSImage object. In the
implemented drawRect: of the NSView, this is the code I use to try and draw
the image onto the view

NSRect bounds = [ self bounds];

float square = MIN( bounds.size.width , bounds.size.height );
float space_between = square * .2 / num_sides ;
float diameter = square * .8 / num_sides ;
NSPoint draw_point = NSMakePoint( 10 , bounds.size.height-10 );
ovalRect = NSMakeRect( 0,0,150 , 150 );
[grid_image drawAtPoint:draw_point
    fromRect:ovalRect operation:nil
    fraction:0.5 ] ;

Needless to say, the image doesn't display correctly. The image is a jpg
75x75.

Anyone have an idea or an example now displaying an image on a NSView?

John<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: drawing NSImage in a NSCustomView 
Back to top
Login to vote
Michael Ash2

External


Since: Mar 01, 2004
Posts: 20



(Msg. 2) Posted: Sat Mar 20, 2004 7:46 am
Post subject: Re: drawing NSImage in a NSCustomView [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sat, 20 Mar 2004, J wrote:

 > Im a newb with ObjC and Cocoa. I have been able to load an jpg from a
 > resource bundle and setImage: in a NSImageView. That works perfectly.
 >
[snip]
 >
 > NSPoint draw_point = NSMakePoint( 10 , bounds.size.height-10 );

Why are you setting the Y coordinate to height-10? If you want to see the
entire image, something like 10,10 would make more sense.

 > Needless to say, the image doesn't display correctly. The image is a jpg
 > 75x75.

Can you be more specific about how it's not displaying correctly? Is it
simply not drawing at all, or is it showing up but in the wrong place,
wrong size, or wrong appearance?<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: drawing NSImage in a NSCustomView 
Back to top
Login to vote
John C. Randolph

External


Since: Feb 25, 2004
Posts: 90



(Msg. 3) Posted: Sat Mar 27, 2004 4:11 pm
Post subject: Re: drawing NSImage in a NSCustomView [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

J wrote:
[snippage]

 > [grid_image drawAtPoint:draw_point fromRect:ovalRect operation:nil fraction:0.5 ] ;

Change 'operation:nil' to 'operation:NSCompositeCopy.' When you
passed nil (that is, zero) as the compositing operator, you actually
told it to just clear the destination.

HTH,

-jcr<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: drawing NSImage in a NSCustomView 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
[XCode] Extensions and NSImage - Hello, I have an application (MyApp) (cocoa-document-based). The document contains mostly a NSImage*. I want that my Application is able to open all typ of images that NSImage support. Th open-function of MyDocument: -(BOOL)readFromFile:(NSString *)...

CustomView & NSImage problem - Hi, I have a CustomView and am displaying an NSImage. The image is higher than the view but instead of cutting off the bottom of the image it cuts off the top. What am I doing wrong? Any help appreciated. Thanks, Paul

Drawing an image in carbon - I am new to Carbon programming and i need help in displaying a RAW 32-bit image in screen. I need an API equivalent to putpixel() in Turbo C++. Also i need an API that allows me to store the Raw image as TIFF or JPEG. Thanx

Drawing Ellipse with Quartz 2D - I want to emulate the behavior of Quickdraw's FrameArc with Quartz in the Carbon API. (FrameArc takes a rectangle and two angles. The total ellipse would exactly fill the rectangle and we only draw the part of the ellipse specified by the angles. If the....

XCode move lost my drawing - Hi, I have a basic program for experimentation where I use BeginFullScreen to get me a blank screen and then do the following simple sequence. Draw something, wait until GetKeys returns something, write time to file, Draw something... Anyway, i...
   Macintosh computer (Home) -> General Discussion All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]