how to load an image to the playground - swift

In the playground app, I am trying to upload an image, I google it and many solutions said that I need to put my image to resources. But the case is that in the new playground app, the is no resources folder that's why I couldn't add my image. There are shared Sources and Xcode sources but in these files, I couldn't put my image.
this can be an easy question but the case that I struggle with. And in order to continue my project, this point madden me. Thanks
as you can see, there aren't resources that ı could put my image
there is space for adding an image but in this case, the problem is that after ı chose my image nothing happened

UIImage can be loaded to the Playground app like this,
File --> New Blank Playground.
Click on the '+" icon on the top right corner and choose the picture by clicking Insert from... option.
Load the image with its name from the Playground.
UIImage(named: "test.png")
Output with loaded image

Related

Image names from assets catalog is not showing up in auto completion - xcode 12

I am trying to set UIColor from image pattern. But I am unable to access the image set by name in xcode 12.
I saved the image set by "BMW" name. I want If I write BMW it should pre-populate in suggestion and small image of BMW should shown up.
I tried to set like this -
node.geometry?.firstMaterial?.diffuse.contents = #imageLiteral(resourceName: "Earth Day")
But it is showing up as
node image
I got it now.
Although images names are still not pre populating, but we can pick the images from assets by typing #imageLiteral() and double click on it, one popup will open that lets you pick any image from assets.
Use UIImage(named:"BMW") to access the image from your assets folder

JavaFX 2.2 generated image not shown after building jar-file

In my JavaFX Application I generate a barcode with barcode4j by Apache, save it as png image in the directory /data/images/ and embed it in a web page which is shown on a JavaFX WebView.
After generating the barcode I embend it into the webpage using the following Javascript-Code:
path = "file:/" + path.replace(/\\/gi,"/");
var barcodeElement = document.getElementById("productBarcode");
barcodeElement.setAttribute("src", path );
barcodeElement.style.display = "inline-block";
I use the absolute path C:\path\to\java-program\data\myimage.png and build a file-URL from it.
Using this in Eclipse works without any problems. But when I build my project and start it from my jar-file the image is not shown. But the problem is not, that the path is incorrect or that generating the picture does not work, so that there is some kind of "not found" error. The place where the image should be is just white with a light border around.
And now the strangest part: If you right click on the image and choose "open in new window" the image is shown!
Does someone has an idea about that?
Thank you very much in advance!
My understanding is that the WebView won't let a page loaded with one protocol access files using another one. This makes perfect sense when you load through http://, and forbid file://. Here, you're loading through jar:file:..., and the webview will only let you access jar:file:... resources (I just tried, I can access an image from another jar file, from the same jar file, but not from outside!).
This sounds very much like a bug to me.
One workaround mentioned here is to use "data:" URI (i.e. encode the image directly in the HTML file).

Could not load the "" image referenced from a nib

I have no images called "" (nothing). I've gone through the .xib file of the screen where this pops up and can't find anything that would cause this. Anybody who have had the same issue? Here is the full warning:
Could not load the "" image referenced from a nib in the bundle with
identifier "com.blah.Blah"
You can do this to check it from your storyboard, or nib.
Open it as Source Code:
Then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
I had the same issue and in my case there was an UIButton with an invalid image reference in the storyboard file. The reference wasn't empty so it was not trivial to spot by just searching for "" in the storyboard file. However, Xcode did show "Unknown image" for the button in the Background field instead of "Default Background Image". In the storyboard file it appeared as
<state key="normal" title="Use" backgroundImage="0E39AEA8-7F29-40B2-96B1-63B99047E8D5">
so perhaps grepping for backgroundImage and looking for non-familiar references will help find the cause.
I had this warning because of a UITabBarItem. In the attributes inspector for the field "Selected Image" I had a file listed that was also the value for the field "Image". Nevertheless, I received warnings until I made the "Selected Image" field blank.
Just for reference, this problem is also caused by using .jpg images and referencing them inside of storyboards/nibs. iOS 8 appears to be able to handle the proper type checking between jpg and png images at runtime. However, on iOS 7 and below you will need to manually set the image in the code and remove the image reference inside of the storyboard to get rid of the warning.
Remember you need to manually set the .jpg when referencing jpg images.
[self.imageView setImage:[UIImage imageNamed:#"yourImage.jpg"]];
I came looking for the answer. I searched my entire project and storyboard source code for "" and nowhere could I find it. The clue that the view that is displayed when the error appears is the one you need.
Open your xib or storyboard selecting the relevant viewController.
On the left click all grey arrows to expand the selection in your
view
look for the UIImageView icon (its the one with the palm tree)
select it and open the "Attributes inspector" on the right hand side.
In the ImageView section at the top in either or both Image and
Highlighted you will see greyed out "unknown image".
Use the drop down menu to change this from "unknown image" and build
run
voila
The nib (or ultimately the xib) that is the cause of the warning message is the one that is loaded when the message gets written. You then can look at the controls that use images in the inspector and find one where the image name is "Unknown image". You can then clear this value by setting it to some value and then clearing out the value. Note that with UIButton you'll need to try the four different values of "State Config" (Default, Highlighted, Selected & Disabled) to see where the invalid reference might be hiding.
In my case it was Unknown image in UIBarButtonItem in storyboard.
Very simple remove the image that is not displaying from you project and then clean the project by going to Product--> clean then once again put the image into your project and done. this worked for me.
In xcode 5.1 I had this same issue. The only way I could finally get it to work when using storyboard was to add the images as an image asset catalog. From what I read maybe they changed something in 5.1. I thought that storyboards don't have nibs - so it would make sense that asset catalog replaces the old method.
Project > General > App Icon Arrow > Import New Folder.
As soon as I did that the NIB references went away and my images showed up.
I'm using Asset Catalog on Xcode 6. Simply removing and re-adding the Asset Catalog fix the problem
in my situation, in my xib file,I had ever setup image name for some UIButton and UIImageView ,and delete these image name after sometime, but for unknown reason, these image still apear in the Interface Builder Editer, finally I reset these image name with any image name and delete them again,now problem resolved.
This worked for me:
1- Quit Xcode
2- Make a copy of your .storyboard for backup.
3- Open your .storyboard in a text editor and delete image nodes and image node attributes with empty references.
delete node like this --> <image name=" " .../>
delete image attributes like this --> <tabBarItem key="tabBarItem" title="untitled" image=" " id="6"/>
4- Save the file
5- Open your project again in Xcode.
6- Run Product->Clean
7- Run your project
Warning should be gone.
I had a very similiar problem which I eventually found. The line below was causing the problem using the open as source code method mentioned above.
<tabBarItem key="tabBarItem" title="Events"
image="319365D1-7058-46CD-8420-18E0EAFB2F29" id="a5a-IF-j9f"/>
I got this error from an undo action, simply dropping the image back onto the view controller solved the problem.
Atb
In my case it was because one of my button images was wrongly added to the Background Image container instead of the Image container (in the Inspector). I found it by going through the entire storyboard hierarchy and checking each image and button setting.
Please do a search for image= shows various results. Select results from nibs or storyboard open it, if there is some value like image="2342D4DF-1E6B-42B8-847A-F9F622921D02" delete it and enjoy.
i also faced same problem because i edited image in photoshop and saved as a psd format make sure you save your edited images in jpg or png format in my case that was the problem hope it helps!!!
I got this problem for all of my images after switching one of the label's text to 'attributed' and using one of the 'Fun' fonts. Even though I switch it back to 'plain' I still get the "Could not load..." error - until I re-load and re-reference all of my images again.
Initially my image name is "bg" When i found issue, i rename image as "background" but when click on image and hit "Show in Finder"changes was not reflected. image was name as "bg-1.jpg".
so i removed from project convert image to png and drag and drop into
project it works for me.
Believe or not, sometimes this happens because some IBOutlet was removed and in the storyboard have the reference to it.
Make sure the 'Target Membership' for the 'Assets.xcassets' has been selected.
Click 'Assets.xcassets'
In the 'File inspector', make sure 'Target Membership' selected.

not able to change image in UIImageView control

This seems to me as a bug because I have changed images with:
someImage.image = [UIImage imageNamed:#"anotherImage.png"];
and I have never had a problem. so let me show you what I have:
I have placed an UIImageView:
note that imgObjetivos is conected to this UIImageView.
I have a method that get's called when clicking the following button:
and the method contains:
as you can see I just want to change the current image with:
so when I run the application in the simulator everything looks great:
and when I press the button the image changes successfully:
Now why is it that when I run the application on my iPad the image does not change!? when I press the button the image disappears instead of getting a new image like in the simulator. I just learned objective-c and I am starting to dislike it. What am I doing wrong?
EDIT
I found a solution I changed the name of the image and now it works:
but this makes no sense. Which names works and which ones do not? I also have make sure that I don't have two images with the same name and that is not the case. when I have a few letters after the '_' underscore it does not work. This is really strange. I am starting to dislike objective-c :(
I've had the same problem before. The problem is that the image that you're using to replace the previous image is corrupted or say is not in it's original format.
In my case, I downloaded images in the web which was .jpg format and renamed it as .png format which actually made it .png. so in short term, ipad does not support the functionality for converting image format by just renaming the extension. you have to have a proper converter or something.
I would go with removing the image file from the project, clean the project and add the file back.
I had to rename the image name to something else I don't understand why... I thought that the problem was because I previously deleted that image that contained the same name but that is not the case because I imported the image with a similar name to the solution and I had the same problem. for example the original name of the image was objetivosFoto_h.png and when I renamed to objetivosFoto_ho.png it still did not work but when I renamed to objetivosFoto_horizontal.png it worked.

iPhone simulator shows app's images but iPhone does not

I have create an application on iphone using objective-c.In this application i am just displaying different players images stored in one folder, which will be run perfectly on simulator. But when I deploy it on iphone it is not showing the images of the player.
for that the code is:
UIImageView *imageplayer = [[UIImageView alloc]initWithFrame: CGRectMake(imgx, imgy+45,135,150)];
imageplayer.image = [UIImage imageNamed:playerpng];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:playerjpg]];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:#"noimage.png"]];
[self.view addSubView:imageplayer];
Plz solve this query.
Thanks in advance
Sometimes xCode doesent update correctly the bundle, try cleaning and building again.
I am currently experiencing this problem as well. I was able to correct it after a bit of debugging and reviewing the build file.
When I do an ls -l, I noticed that some of my png files have a # symbol beside the permissions. When I followed that up with a ls -l#, it showed that the files with an '#' had an attribute set 'com.apple.quarantine'. This attribute is given to a file (often from a zip, jar, or other executable) that is downloaded from the net. You can get rid of this attribute by performing:
xattr -d com.apple.quarantine *.png
Then, select the images in XCode, and check that the checkbox under the target is checked. In my case, it was not, so the images weren't being included in the bundle.
I had the same problem, solved by using all lowercase for the file name in code - image.jpg, but it does not seem to make any difference what case the actual file name is, e.g. Image.jpg
check name of image file. It must be "noimage.png"
not Noimage.png or noimage.PNG
Just to clarify, does the "noimage.png" display, or is the program loading a player image but failing to display it? Or is nothing loading.
These should easily be determined in debug mode.
A few additional things to check...
1) Just for testing, start out with PNG versions of the player files. This is the primary format on the iPhone and might eliminate a file format issue or other anomaly that the simulator is not sensitive to.
2) With regard to fixing in an image editor, specifically make sure that the image is set to a DPI of 72 pixels/inch. The iPhone and particularly Interface Builder are very sensitive to this being correct and will sometimes not display or will display a very blurred version of the image if incorrect.
3) Make sure the image(s) haven't been added multiple times (from different directories and/or to different group folders). We encountered a situation where we had inadvertently imported the same images at two different layers within the project hierarchy and this can cause unexpected behavior within the iPhone (selecting randomly or failing to select).
4) Make sure the Get Info -> Targets has your particular target checked. The simulator may still see the image but it will not get deployed to the iPhone.
5) Make sure you can view the image within XCode and that it looks correct.
Barney
This happens to me sometimes. I once spent half a night trying to figure out what was wrong. In this end, this is what worked: open the image with an image editor and save it again. That's all. I'm using the free Acorn image editor to do this. Haven't tried it with Photoshop. (After all, it seems that Photoshop might be responsible for introducing the error in the first place, although that's far from sure.)
I don't know what causes the problem. I usually get it when I use png files that have been sent to me. Could be a simple file permissions problem, or some more subtle problem with the image format. I would be very interested in hearing the opinion of better-informed people.
In any case, if all else fails just try this: open the image with Acorn, save over the original file. Works for me.
Make sure the image files are added to your XCode project.
After some investigation, Michael's comment seems to have a solved it for me. I had all lower case as the file name but was following variable convention and had the png file with an upper case for the second part of the file name. Here my file was putback.png but was referenced in my code as putBack.png
UIImage *putBackImage = [UIImage imageNamed:#"putBack.png"]; //wrong
UIImage *putBackImage = [UIImage imageNamed:#"putback.png"]; //correct
Select correct target while adding image files to your project. Following are steps to make it further clear
Select Add Files to "YourProjectName"
In opening window there is an "Add to targets" option at bottom that shows all available targets
Check target or multiple targets in which you want to add images
Press "Add" button and you are ready to go