I am trying to make a simple game, so far i can capture user input, but i cannot get the view to work properly to print the images. If i have a resource named image, how do i assign individual sprites to display this image on displayOn? I have tried many approaches, for example in the initialize method i tried:
self image := Classname image
but that caused an overflow, and i was forced to closed visual without saving work.
What is the good way to do this?
you usually access to class side methods directly, without needing to store there into instance variables. For example:
myMethodsWhoNeedsAnImage
| image |
image := self class imageStoredInClassSide.
"now do something with image"
If you need to store it, certainly you cannot do what you tried in your example, but you can do:
initialize
super initialize.
image := ClassWithImage image.
or
initialize
super initialize.
self image: ClassWithImage image. "This is a setter method"
Any of these approaches should work. If it doesn't, most probably you have a problem somewhere else, not in the accessing to class side.
Related
To clarify this at the beginning:
With image inside the mask of subsystem i do NOT mean an image drawn onto the block, but rather an image one can add to the mask:
Is there a way to bind the image to the block? In case I want to distribute my model, I don't want to have to share every image used in it.
For an image drawn onto the block I found a solution here, that is storing the image inside the UserData of the block, but I can't find an option to change the properties of images used inside a mask.
This might be a bit too late, but having the same problem I 'fixed' it by including the image and its alpha values in the 'UserData' parameter, checking if the image already exists in the current folder, and if not creating it from the userdata:
if ~exist('ARMicon.png','file')
maskParams = Simulink.Mask.get(gcb);
armim = maskParams.getDialogControl('armPic');
ud = get_param(gcb,'UserData');
imwrite(ud.ARM,'ARMicon.png','Alpha',ud.alpha);
armim.FilePath = 'ARMicon.png';
end
Hope this helps.
Quote out of my correspondence with the MathWorks Technical Support:
Unfortunately, it is currently not possible to specify a mask dialog image without providing a file path and a separate image file. This has been brought to the attention of the development team as a possible enhancement for a future release.
This refers to Matlab / Simulink 9 (2016a).
A beginner volt question here :-).
I’ve created a simple volt app which pulls random images from the file system - a slide show. The image data is retrieved in a server task (in addition to the file path, I want dimensions orientation etc, so I use a ruby library) and then its passed back to the main controller. So I have a method (get_random_pic) in the controller which sets the img path etc on the page for a img tag to use in the view:
<img width="{{page._image_data[3]}}}}" src="{{page._image_data[0]}}">image</img>
(An aside: I am using an array in an effort for the value binding "signals" to arrive at the same time - otherwise the image width updates at a different time to the image path - however its still not synchronous with an array)
Then I use setTimeout in the controller to call the get_random_pic method again (via a button).
setTimeout(function(){ document.getElementById("myButton").click(); }, 5000);
This works perfectly however memory usage never stops growing (e.g. after 20min it will 2GB). I assume this is because each time the image is being loaded in the view, the previous image is orphaned and the GC can’t run. Actually I don’t know enough about JS to come to any intelligent reasons as to why, nor an elegant work around. Maybe I could load up the image in a controller instance method and the img tag references directly the binary (rather than pull via file path from file system), and on each iteration I could set it to nil, but I’m hoping there is nicer solution, before I try that.
I'm not finding much documentation on embeding images in .as files. Really, I'd like to have some theory on it. So far from what I got reading here and there:
I placed an image in Assets folder inside src. Then right-clicked the image and clicked "Generate embed code", then this code line appears where the cursor was [Embed(source="fluffybunny.png")] what now? How do I assign it to a variable or something... I really didn't find it out there.
Instead of given object using .graphic atribbutes I want to use an image.
Also, does it have to be an .SWF?
There are quite a few resources on this (when you search for "as3 use embed tag"). Some of them are really helpful:
http://www.bit-101.com/blog/?p=853
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html
The most basic thing is that you declare a variable of some type. And you use the [Embed] tag before the variable declaration. It's some kind of weird association. Something like:
[Embed(source="image.jpg")]
public var imageClass:Bitmap;
// later on you can instantiate it and use:
addChild(new imageClass()); // creates and adds new image
This is just a sample - there are a lot of types and ways to do it - give a shot the Adobe reference, there are tons of samples.
I want to generate a ton of dummy data - part of that data is images of various sizes. From avatars to banners to other image sizes in between.
How do I go about doing that dynamically, in my Rails 3 app, if not with Factory Girl?
Thanks.
P.S. It would also be great if that method can handle pushing the images to S3. As in, my app is configured to use CarrierWave & Fog to push images to S3. So whatever I use for dynamic image generation just needs to work with that.
I would probably do this with RMagick, a Ruby front-end to ImageMagick. I imagine you could just create a simple class that takes your width/height parameters and generates something like a rectangle with a red x running from corner to corner. It's fairly well documented, so this should be pretty easy to do.
I haven't used CarrierWave, so I can't offer advice there. If you can just feed it a file path, you should have no trouble if you include a public method to return the dummy file path.
I'm trying to display an NSTableView of:
| thumbnail | filename |
I created the NSTableView in IB and delegated it to a class. In the class, I bypassed a model just to get a POC implementation and created the data source delegate methods. They populate the text cells just fine. However, now I'm at the step where the first cell needs to contain a small thumbnail of the image.
What I want to do (and I'm sure it's stupid-simple) is grab the image icon -- and it's fair to assume that all files are jpegs and have thumbnails embedded -- and put that icon, scaled to 64x64 into the table cell. There's lots of code on how to generate thumbnails but I don't see much that gets me to working code. Here's what I have:
# This works if I am only populating text values in the when 'Image'
def tableView_objectValueForTableColumn_row_(image_table, column, row)
thumbnailImage(75)
case column.headerCell.stringValue
when 'File Name'
(0..99).to_a[row].to_s
when 'Image'
# here's where I want to return a square 64x64 image or ImageCell
thumbnailImage(64)
else
'???'
end
end
# Creates square thumbnail
def thumbnailImage(size)
file = "file://localhost/Users/sxross/Downloads/iStock_000004561564XSmall.jpg"
image = CGImageSourceCreateWithURL(CFURLCreateWithString(nil, file, nil), nil)
thumb = CGImageSourceCreateThumbnailAtIndex(image, 0, nil)
thumb
end
def numberOfRowsInTableView(view)
100
end
What I'm grappling with is what the missing steps are to get the thumbnailImage method to provide me with something that can be an appropriate data object to return from the data source.
Any help is amazingly appreciated.
BTW: IknowIknowIknow, I should be using MacRuby but it doesn't run on my 32-bit Core Duo. Sadly.
I bypassed a model …
Don't do that. In Cocoa, it's easier to do things with a model than without.
What I'm grappling with is what the missing steps are to get the thumbnailImage method to provide me with something that can be an appropriate data object to return from the data source.
CGImageSourceCreateThumbnailAtIndex returns a CGImage. You need tableView_objectValueForTableColumn_row_ to return an NSImage. Therefore, use NSImage's initWithCGImage_size_ method.
If you're running Leopard, that method isn't available, so you'll need to create an NSBitmapImageRep with the CGImage instead, and then create an NSImage of the correct size and add that representation to it.