How do I change the background image of some canvas from withing the c# code on button press? I know how to change the background color:
Canvas1.Background = new SolidColorBrush(Colors.Red);
I found a tutorial online , but VS says that "The type or namespace name 'BitmapImage' could not be found (are you missing a using directive or an assembly reference?)"
var brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(#"Images/myImage.png", UriKind.Relative));
Canvas1.Background = brush;
What am I missing?
TIA!
You need to add a reference to the System.Windows.Media.Imaging namespace. Add this to the top of your class, where the other using directives are.
using System.Windows.Media.Imaging;
Related
In my Xamarin.IOS visual studio project, I wanted to use Vector pdf image in an UIImageView. But I am not able to add the vector image directly in the storyboard designer (also tried drag-drop).
Is there a way to use Vector pdf image in xamarin IOS?
Any sample would be much helpful.
Thanks.
Yes, As lowleetak said, We need to add the pdf file into the asset first.
Xamarin tutorial here , just follow the step ,it's simple.
Edit:
there is no option to select the Attributes Inspector for setting the Scales to Single Vector in Visual Studio. Is there an alternative for this?
AFAIK,there is no option to set the scale for the vector , maybe you could set this property when generate the pdf file.
I want to handle click event to capture the image X Y co-ordinates in C#. Is there a way to do this?
Override the touch event . documentation here.
Code :
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
var touch = touches.AnyObject as UITouch;
CGPoint point = touch.GetPreciseLocation(yourImage);
}
Update:
On iPhone5:
On iPhone6
And this are the constraints
You will need to add the pdf images to asset catalog first (Images.xcassets). You can refer to the guide HERE. It is a guide for Xcode but should be quite the same in Visual Studio.
Can we get the bitmap directly from FFImageLoading? I know i can use CachedImage View but I am currently using NControl and NGraphics to do custom drawing with touch events
ImageService.Instance.LoadUrl(urlToImage)
.Into(nativeImageView);
OR
var drawable = await ImageService.Instance.LoadUrl(urlToImage)
.AsBitmapDrawableAsync();
var image = ImageService.Instance.LoadUrl(urlToImage)
.AsUIImageAsync();
I've been able to add images as textures on ViewPort2DVisual3D by simply setting the 'Value' field with an Image.
But now I'm trying to use the helix tools and I can't find a way to do the same on a MeshElement3D.
I've been trying with a RectangleVisual3D, but there's nothing such as a 'Visual' field on it.
I bet I should try with the 'Material' field, but all I found is the ImageMaterialExtension object.
But it is not inheriting from Material so I can't give it to my RectangleVisual3D.
Any advice?
I found the solution, we can just use the Material Helper such as :
var mat = MaterialHelper.CreateImageMaterial("img.png", 1, UriKind.Absolute);
and add it to the Material of the MeshElement3D
I'm fairly new to C++ in general, so I need a little help with Qt. I'm trying to add an image to a PushButton, and I keep having problems with it. Here is an example of what I have:
#include <QtWidgets/QPushButton>
QPushButton *button;
button = new QPushButton(Example);
button->setObjectName(QStringLiteral("button"));
button->setGeometry(0,0,128,56);
So I have a picture saved in /example/pics/example.png (example being the project name), and I would like to use it on the PushButton. I've been messing around with it for a while, and can't find a solution, so any help is appreciated.
button->setIcon(QIcon("/example/pics/example.png"));
In pyqt5/pyside2, this is what I used:
icon = QIcon()
pixmap = QPixmap(r'C:\Users\git\Desktop\test.png').scaled(QSize(160, 90))
icon.addPixmap(pixmap, QtGui.QIcon.Normal, QtGui.QIcon.Off)
pushButton.setIcon(icon)
pushButton.setIconSize(QSize(160, 90))
pushButton.setStyleSheet("QPushButton{border-radius:5px;border: 1px solid #345781;}")
I need to get a label image into a Qt Widget
I have tried putting a label on the widget then just on its properties on the right under text i selected pixmap and selected the image I wanted to use.
However when I run the program no image appears any ideas why this is?
I have also tried :
QLabel label("<img src='image.jpg' />");
label.show();
But had no luck do not think I was using it right
Official way of "adding image to QLabel" provided by Nokia Corp. A QPixmap is used.
QLabel label;
QPixmap pixmap(":/path/to/your/image.jpg");
label.setPixmap(pixmap);
label.setMask(pixmap.mask());
label.show();
QIcon searchIcon = Icon::fromTheme("edit-find");
searchLabel->setPixmap( searchIcon.pixmap(16,16) );
Another way is to use Qt Style Sheets.
QLabel label;
label.setStyleSheet("background-image: url(:/images/assets/your.png)")