I want to show a background image on my app's navigation bar.
Showing the image works:
UIImage image = new UIImage( #"Images/navbarlogo2.png");
UIImageView imageview = new UIImageView(image);
NavigationItem.TitleView = imageview;
But the image is centered, while I need it to be right-aligned.
I have not been able to find a property to do this, and searching yielded no answers.
You could use the following method to set your navbar's background image. Note that this will set it as the default for all the nav bars and is available since iOS5.
UINavigationBar.Appearance.SetBackgroundImage(image, UIBarMetrics.Default);
Related
I'm trying to add .ico 48x48 image before text in WinForms button 87x30 size:
button1.BackgroundImageLayout = ImageLayout.Stretch;
button1.BackgroundImageLayout = ImageLayout.None;
button1.BackgroundImageLayout = ImageLayout.Zoom;
button1.ImageAlign = ContentAlignment.MiddleLeft;
button1.TextImageRelation = TextImageRelation.ImageBeforeText;
button1.TextAlign = ContentAlignment.MiddleRight;
Result is:
I'm trying to figure out, how to align image on the left side with text on related distance, like this:
edit:
button1.TextImageRelation = TextImageRelation.ImageBeforeText;
button1.TextAlign = ContentAlignment.MiddleLeft; /// MiddleRight; // MiddleCenter;
button1.ImageAlign = ContentAlignment.MiddleRight; /// MiddleLeft;
Result:
The background image property is like the operating system desktop background, it is a wallpaper, that can be stretched, adapted, repeated...
Therefore here you don't need to use BackgroundImage for a button icon style image associated to its text.
If you use the Image property and set alignments to left for it and right for text, all works fine:
Then you can adapt these alignments as well as width and height to the desired result depending on the image size and/or text size and length.
Also, as indicated by the duplicate I finally found, to simply center all, you can use the TextImageRelation and set it to TextImageRelation.ImageBeforeText without changing alignments, and if necessary by increasing the height according to the size of the displayed image to have a clean result:
i create a panel and inside this panel i create a picture box. this have no default image. after a function i load a image und put it into this picturebox. the image was bigger as the panel and i want to scroll the image but the image draw only in the first area to see and if i scroll the image dont draw complete. how i can fix this ?
Image TreeImg = new Bitmap(imgPath);
maletreePictureBox.Width = TreeImg.Width;
maletreePictureBox.Height = TreeImg.Height;
maletreePictureBox.Image = TreeImg;
actionPanel.AutoScrollMinSize = new Size(TreeImg.Width, driverTreeImg.Height);
this is the result
Set the .Dock property of the maletreePictureBox to Fill.
Also it looks like your AutoScrollMinSize Height property is incorrect (driverTreeImg.Height instead of TreeImg.Height)
I use the imagebox to display a image(imgWidth:19200, imgHeight:260),and my code is:
imageBox = new ImageBox();
imageBox.Size = new Size(imgWidth, imgHeight);
imageBox.Dock = DockStyle.Fill;
MainSplitContainer.Panel1.Controls.Add(imageBox);
imageBox.Image = new Image<Bgr, byte>("2.bmp");
But the displayed image width is only about 15000, and the right part of the image can not be displayed. How can I display the full image?
It is possible that an ImageBox won't do more than 15,000 pixels in width. However, have you tried setting the functional mode to Pan and Zoom? Maybe that will get you there.
Doug
I am trying to create a bitmap copy of a view to use it as a drag shadow for a drag & drop operation.
I have used the techniques described here:
How to capture UIView to UIImage without loss of quality on retina display
How Do I Take a Screen Shot of a UIView?
How to get a color image in iPhone sdk (to render a solid fill into the view, resulted in an empty image too)
But the result is always a transparent/empty image (it's not nil/null, I checked)
The views I'm trying to copy contain (transparent) SVGs.
Here is my code:
// always results in an fully transparent/empty image
private UIView CreateDragShadow(UIView view)
{
UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, 0.0f);
CGContext context = UIGraphics.GetCurrentContext();
//view.DrawViewHierarchy(view.Bounds, true); // "old" way
view.Layer.RenderInContext(context); // recommended way
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
UIImageView dropShadow = new UIImageView();
dropShadow.Image = image;
return dropShadow;
}
I have also written a little test function to see if the view gets added to the superview correctly, which works and correctly produces a white UIView with "Drag shadow" written on it:
// this produces a white drag shadow image with "Drag shadow" written on it
private UIView CreateDragShadowTest(UIView view)
{
// test with a simple UITextView to see if the approach works
UITextView viewTestShadow = new UITextView(view.Frame);
viewTestShadow.Bounds = view.Bounds;
viewTestShadow.Text = "Drag shadow";
return viewTestShadow;
}
Does anybody know what's going on?
I'm also open to entirely different ways of doing this.
Best regards!
I have since found an answer on the Xamarin documentation page that I couldn't find mentioned anywhere else when searching SO
The new code is:
private UIView CreateDragShadow(UIView view)
{
UIView dropShadow = view.SnapshotView(true);
return dropShadow;
}
Which exposes snapshotViewAfterScreenUpdates (found here: Apple Doc snapshotViewAfterScreenUpdates) and conveniently produces a UIView snapshot.
This solution has worked for me, but I would still like to know what I was doing wrong with the other approaches, if anybody knows.
So, I'm trying to save an canvas content as an image. I'm using this for it:
var img = new WriteableBitmap(myCanvas, null);
Problem is that the image is not showing all the content inside of the canvas. If there's a button, an image or other similar objects, they do not show.
I can see an ellipse, but if I set an image as background, the background stays empty.
Is there anyway to solve this?
Try to use Image Tools from codeplex and read this and this