how to set a paintdrawable as view background? - drawable

I'm trying to set a PaintDrawable as a background for a view in order to change the color dynamically and keep the borders but when i write :
vi.setBackground(pd);`
i got an error : NoSuchMethodError
here is my code :
PaintDrawable pd = new PaintDrawable(color);
pd.setCornerRadius(4);
pd.setPadding(1, 1, 1, 1);
vi.setBackground(pd)
DyL.addView(vi);

setBackground(Drawable) was introduced in Android SDK 16. If you want compatibility with earlier SDKs you should use the deprecated setBackgroundDrawable or explicitly test the SDK version.

Related

Xcode 10 - image literals no longer available

Xcode 10 Release Notes: "Code Completion for Swift image literals has been removed in Xcode 10"
So it's not a bug that I couldn't add images in the code (and run older projects). How do we then add images from now on in the code as just typing UIImageView(image: won't accept any png or jpeg.
let cellImage: UIImageView = {
let image = UIImageView(image: ???))
return image
}()
System: macOS Mojave
Xcode: Xcode 10 Beta 4
In Xcode 10 and Swift 4.2, only the code completion function (or auto-complete) of the Xcode IDE has been discontinued for the old way. Here is the new way:
Just type image literal and it will complete with default icon.
Double click on this icon and it will open the media library right side of it.
Just choose your imagem and it work like before!
Found the Shortcut to open the Media Library Tab:
⇧+⌘+M
At this point the official documentation does not cover some use cases at Xcode 10 beta so I'm not able to find a way to move the media part to the old position.
You can use Media Library in Xcode to add image literal to your code:
And then choose image from library and drag&drop it to your code
It will create image literal
For the benefit of others with legacy code that utlizes Swift Image Literals, the code and syntax of the image literal function themselves are still valid and work perfectly fine in Xcode 10 with Swift 4.2.
There is no need to rollback or refactor existing code that utlizes these image literals, and they can still be used as follows:
imageView.image = #imageLiteral(resourceName: imageNameString)
Only the code completion function (or auto-complete) of the Xcode IDE has been discontinued.
UPDATE
The difference in image-literal representation in previous and current versions or Xcode/Swift:
image = #imageLiteral(resourceName: "flower.jpg")
As the extract illustrates, image literals were represented in-line with thumbnails of their actual image. However, now, only a generic icon is used in its place. Presumably, this goes towards reducing the burden on the IDE, by eliminating the overheads of handling and displaying the in-line thumbnails.
TIP: To fix three resolutions after add a literal image in code.
1. Remove another, keep only one image
2. Comment your line code with literal image, then will appear literal image in code, like: #imageLiteral(resourceName: "image#2x.png"
3. in resourceName value, remove #2x and file extension, like .png, keep only image name: #imageLiteral(resourceName: "image")
4. Uncomment! Image will be showed in code.
In Xcode 11, the media library is now under View > Show Library (SHIFT+CMD+L).
If anyone using Xcode 11 then you can find all media using below option:
Using
UIImage(imageLiteralResourceName: 'imageName')
won't return an optional and works just fine
Just use #imageLiteral(
It will work
i'm using Xcode 10 beta 4 and i have the same problem !
Resolved using the old way to pass an image
PizzaModel(
nome: "Marinara",
ingredienti: "Pomodoro, Aglio",
calorie: "729",
img: UIImage(named: "marinara")!
)
you can use this code in Xcode 14.1
"UIImageVievName".image = #imageLiteral(resourceName: "imageName")
and then you can click the photo icon, you can chose what you want to add the image.
Just type command+shift+L , you will get the option for image addition.

Unity3d 4.6 UI Image bug on some Windows 8 and 8.1

I'm making an interactive book for windows users and i'm using 4.6 UI system. I tested my application on lots of computers using various windows versions. It works fine with windows xp, windows 7, windows 8 and 8.1. But some of the windows 8 and 8.1 computers are producing a weird bug.
Here is how it should look like
and here it is in windows 8
Btw i have lots of images in my application. I'm putting them in my project with .bytes extension and creating sprite on runtime. My code to do this is :
void TextAssetToSprite(int pNo)
{
TextAsset tmp = textAssetArray[pNo] as TextAsset;
Texture2D imgTexture = new Texture2D(1, 1);
imgTexture.LoadImage(tmp.bytes);
Rect rectangle = new Rect(0, 0, imgTexture.width, imgTexture.height);
Vector2 pivot = new Vector2(0.5f, 0.5f);
Sprite firstSprite = Sprite.Create(imgTexture, rectangle, pivot);
imageControl.sprite = firstSprite;
tmp = null;
imgTexture = null;
Resources.UnloadUnusedAssets();
}
I don't know what i'm doing wrong. I've done hours of research but found nothing similar. When i create sprite in the editor and use it on UI image component it works as expected but it's not an option because there are lots of png images in my application and it's size will be too much. Please suggest me a way to fix this. Any help will be greatly appreciated.
It's been a long time since I posted this. I don't know if unity fixed the issue or not. Problem was when I was creating the Texture2D I was just giving it width and height parameters but some operating systems change the default settings for Texture2D. So here is the solution. Change
Texture2D imgTexture = new Texture2D(1, 1);
to
Texture2D imgTexture = new Texture2D(2, 2, TextureFormat.RGB24, false);

iOS 8 - Background gradient for launch screen file

How would you apply a background gradient to a launch screen file?
Are you supposed to just include large image for the background or can you run code in a launch screen file to do custom drawing?
You cannot run code or use any custom classes in the Launch Screen.
You'll have to supply a stretchable image, which contains enough data for it to be viable in all resolutions.
Also, you could take advantage of the #2x and #3x modifiers.
iPhone 6 plus will try to load a #3x modifier, AFAIK.
As a last resort, if the Launch Screen xib is not enough for you, you could still use the UILaunchImages plist key, and specify images for minimum version of 8.0. The downside is that Xcode does not automatically generate those for you, so you'll have to write those manually. Also remember that the modifier for iPhone 6 plus images is #3x
An example:
UILaunchImage = Default // This is for iOS 6, if you need it
UILaunchImages // iOS 7, 8
- [0]
- UILaunchImageName = Default
- UILaunchImageMinimumOSVersion = 7.0
- UILaunchImageSize = {320, 480}
- UILaunchImageOrientation = Portrait
- [1]
- UILaunchImageName = Default-568h
- UILaunchImageMinimumOSVersion = 7.0
- UILaunchImageSize = {320, 568}
- UILaunchImageOrientation = Portrait
- [2]
- UILaunchImageName = Default-667h
- UILaunchImageMinimumOSVersion = 8.0
- UILaunchImageSize = {375, 667}
- UILaunchImageOrientation = Portrait
- [3]
- UILaunchImageName = Default-736h
- UILaunchImageMinimumOSVersion = 8.0
- UILaunchImageSize = {414, 736}
- UILaunchImageOrientation = Portrait
P.S. The plist above is also a perfect solution for those who are struggling with the localization of Image Catalogs or Launch Screen files.
As long as you can add PDF single vector assets to your projects, I usually export gradients that have to be in launch image from Illustrator or Photoshop to PDF and include them in the layout with pretty good results.

OpenCV trackbar performance in OSX

I've just noticed that performance of openCV is drastically slowed down when a trackbar is present in a window with changing image from camera or a movie frame. What could be done resolve this issue?
The solution to that is to move trackbars to a separate window. For me on OSX the performance increased 4.7 times (from 3 FPS up to 14). I don't know if it works like this always or it's just like that on my computer but I haven't seen such a clue anywhere before so I decided to share.
string title = "My window";
int p = 2;
// Create a different window for controls
namedWindow(title + " - controls");
// I show an image once just to resize the window
imshow(title + " - controls", Mat::zeros(1, 500, CV_8UC1));
createTrackbar("Parameter", title + " - controls", &p, 3);
// Create a different window for actual image
namedWindow(title);
while (!done) {
// Do some calculations
flip(image, image, p);
imshow(title, image);
}
I also encountered the same problem in OSX-10.9.
And I have resolved the issue in the following ways:
port variants opencv
sudo port install opencv +qt4 +tbb +eigen +opencl
important option is "+qt4" only, the other options are extra.
OpenCV support Qt for GUI backend. And I suspect the cause of the problem is in the implementation of the default GUI backend.
I was able to virtually eliminates the problem by re-build OpenCV library with Qt support and re-install(update).
For me, this seemed to be an issue with the Anaconda distribution of OpenCV.
Installing OpenCV with pip fixed my performance issues.
Try to tune
cv2.waitKey(value)
I used cv2.waitKey(100) and works smoothly

JFreechart image is not created using OpenJDK

I have compiled OpenJDK in ubuntu and installed the JRE to another Linux system.
I am creating a Chart image using jFreechart using openjdk and saving it as JPG. The output image is having only the white background and the chart lines are missing. The same code works fine in Windows with openjdk.
I guess some dependencies are missing but i am not able to find it. Could any one list the dependencies of openjdk. It has requirement of native libraries in Linux.
I am also getting an exception related to Fonts (sun.awt.X11FontManager.getDefaultPlatformFont(X11FontManager.java:779)). What is the default font location for OpenJDK? It is not looking in to the fontconfig.properties file.
While I don't know how to help with your exact problem, you could consider trying a different Java Charting API. I prefer XChart, and if you just need a line or scatter chart and PNG format is OK, it would be very easy to just try it out on Ubuntu quickly. Taken from here (Example 1), this is all the code you would need:
// Sample Data
Collection<Number> xData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0 });
Collection<Number> yData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0 });
// Create Chart
Chart chart = new Chart(500, 400);
chart.setChartTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
chart.addSeries("y(x)", xData, yData);
BitmapEncoder.savePNG(chart, "./Sample_Chart.png");

Resources