I am trying to resize a SystemIcon for use within a ErrorProvider.
Dim WarnProvider As New ErrorProvider
WarnProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink
WarnProvider.Icon = SystemIcons.Information.Clone()
WarnProvider.Icon.Size = New Size(16,16)
But the SystemIcons has the size set as a read only property.
Been messing with it for the past hour and have not found any good methods to make this work.
Can someone help?
Thanks
I was looking for the a method to do this as well, and came across this post. Here's what I ended up doing to resolve the issue.
I created a global static method to resize an icon.
public static class Global
{
public static Icon ResizeIcon( Icon icon, Size size )
{
Bitmap bitmap = new Bitmap(size.Width,size.Height);
using( Graphics g = Graphics.FromImage(bitmap) )
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(icon.ToBitmap(), new Rectangle(Point.Empty,size));
}
return Icon.FromHandle(bitmap.GetHicon());
}
}
Then I applied the icon in the constructor of the form after InitializeComponent() was called.
public SpecificationsDialog( int pid )
{
InitializeComponent();
warningProvider1.Icon = Global.ResizeIcon(SystemIcons.Warning,SystemInformation.SmallIconSize);
}
I was looking for the same thing and found the answer elsewhere, so I'll post here
http://www.codeproject.com/Questions/242780/error-provider-problem
WarnProvider.Icon = new Icon (SystemIcons.Warning, 16, 16);
or
WarnProvider.Icon = new Icon (WarnProvider.Icon, 16, 16);
I changed Drew's solution a little to be an extension method for the errorprovider:
public static ErrorProvider SetIcon(this ErrorProvider errorProvider, Icon icon, Size size)
{
Bitmap bitmap = new Bitmap(size.Width, size.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(icon.ToBitmap(), new Rectangle(Point.Empty, size));
}
errorProvider.Icon = Icon.FromHandle(bitmap.GetHicon());
return errorProvider;
}
Then it's can be used like so:
ErrorProvider ep = new ErrorProvider();
ep.SetIcon(SystemIcons.Asterisk, new Size(16,16));
Related
This is fairly straight forward, but I have some custom ShellRenderers for my App in Xamarin Forms, and I'm having issues with the scaling of images. In particular, Android looks fantastic with the more pixel-dense image (800x200). It looks great on every screen.
The renderer just ensures that the top of the screen is made of the "theme" color, and is presented in the center of the it. It's that simple/straight-forward.
On iOS, it looks awful and blurred. I'm not sure if there's something I need to set or update (or maybe a different graphics stack?) to make it render with higher pixel density... See my attached renderer:
public class CustomShellRenderer : ShellRenderer
{
#region Methods
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection);
if (renderer != null)
{
var navigationBar = (renderer as ShellSectionRenderer).NavigationBar;
if (navigationBar != null)
{
navigationBar.BarTintColor = Colors.LightColor.ToUIColor(); //static colors
navigationBar.TintColor = Colors.LightColor.ToUIColor();
using (var logo = UIImage.FromResource(typeof(Images).Assembly, "Path.To.Logo.png"))
{
var statusFrame = UIApplication.SharedApplication.StatusBarFrame;
var navigationFrame = navigationBar.Frame;
var width = Math.Max(navigationFrame.Width, statusFrame.Width);
var fullArea = new CGRect(0, 0, width, navigationFrame.Height + statusFrame.Height);
UIGraphics.BeginImageContext(fullArea.Size);
var backgroundColor = Colors.PrimaryColor.ToUIColor();
backgroundColor.SetFill();
UIGraphics.RectFill(fullArea);
var logoArea = new CGRect(width * .35, statusFrame.Height, width * .3, navigationFrame.Height);
logo.Draw(logoArea);
var backgroundImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
(renderer as ShellSectionRenderer).NavigationBar.SetBackgroundImage(backgroundImage, UIBarMetrics.Default);
backgroundImage.Dispose();
}
}
}
return renderer;
}
#endregion
}
Any thoughts? Right now, the problem is that when it renders, there is an 800x200 image trying to squeeze into... 140x30 or so space on some emulators...
Thank you!
For personal needs, for the Xamarin.Forms.Map control, I need to create a CustomPin extension. UWP part (PCL project)
I create a MapIcon like it:
nativeMap.MapElements.Add(new MapIcon()
{
Title = pin.Name,
Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Pin/customicon.png")),
Location = new Geopoint(new BasicGeoposition() { Latitude = pin.Position.Latitude, Longitude = pin.Position.Longitude }),
NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0)
});
However, by this way, I can't set the Image's size.
I then want to use an Image from my PCL part, resize it and convert it into a IRandomAccessStreamReference. To realize it, I need to convert my Image into a stream, but I can't find the way to make it works ><
Example of the function needed:
private IRandomAccessStreamReference ImageToIRandomAccessStreamReference(Image image)
{
//Here I can set the size of my Image
//I convert it into a stream
IRandomAccessStreamReference irasr = RandomAccessStreamReference.CreateFromStream(/* img? */);
//irasr is then created from img
//I return the IRandomAccessStreamReference needed by the MapIcon element
return irasr;
}
Note: The Image paramter img is a Xamarin.Forms.Image
So first, is it possible? If yes, then thank for any help which could help me.. I already search about how to resize the MapIcon and it's not possible directly from the class [MapIcon].(https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.maps.mapicon.aspx)
Thank for help !
You are right. We can't resize the MapIcon directly as it doesn't provide such properties or methods. MapIcon's size is mostly controlled by the size of image which is set by MapIcon.Image property. And we can set this image's size without using Xamarin.Forms.Image.
To set this image's size, we can take advantage of BitmapDecoder class, BitmapEncoder class and BitmapTransform class like following:
private async System.Threading.Tasks.Task<RandomAccessStreamReference> ResizeImage(StorageFile imageFile, uint scaledWidth, uint scaledHeight)
{
using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
{
var decoder = await BitmapDecoder.CreateAsync(fileStream);
//create a RandomAccessStream as output stream
var memStream = new InMemoryRandomAccessStream();
//creates a new BitmapEncoder and initializes it using data from an existing BitmapDecoder
BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(memStream, decoder);
//resize the image
encoder.BitmapTransform.ScaledWidth = scaledWidth;
encoder.BitmapTransform.ScaledHeight = scaledHeight;
//commits and flushes all of the image data
await encoder.FlushAsync();
//return the output stream as RandomAccessStreamReference
return RandomAccessStreamReference.CreateFromStream(memStream);
}
}
And then we can use this method to create a resized image stream reference first and then set it as MapIcon's Image like:
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Pin/customicon.png"));
var imageReference = await ResizeImage(file, 64, 64);
nativeMap.MapElements.Add(new MapIcon()
{
Title = pin.Name,
Image = imageReference,
Location = new Geopoint(new BasicGeoposition() { Latitude = pin.Position.Latitude, Longitude = pin.Position.Longitude }),
NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0)
});
How to generate image as Thumb in simple way i think minimal coding on asp.net,
Then after how to save particular folder
I would not recommend to use the "Image.GetThumbnailImage" method because of the poor quality
(search "Image.GetThumbnailImage quality" on your favorite search engine...)
Here is a code snippet:
void GenerateThumbnail(string sourceImagePath, string destImagePath, int width, int height, System.Drawing.Imaging.ImageFormat destImageFormat)
{
using (var destImage = new System.Drawing.Bitmap(width, height))
{
using (var g = System.Drawing.Graphics.FromImage(destImage))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
using (var sourceImage = System.Drawing.Image.FromFile(sourceImagePath))
{
g.DrawImage(sourceImage, new System.Drawing.Rectangle(0, 0, width, height));
}
destImage.Save(destImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
OR - you can use Piczard (Piczard)
Here are some usage examples:
// 50% thumbnail (Jpeg image format)
var filter = new CodeCarvings.Piczard.ImageTransformation(50);
filter.SaveProcessedImageToFileSystem("~/MySourceImage.jpg", "~/MyDestImage.jpg");
// Fixed size thumbnail 400x200 (PNG image format)
var filter2 = new CodeCarvings.Piczard.FixedResizeConstraint(400, 200);
filter.SaveProcessedImageToFileSystem("~/MySourceImage2.jpg", "~/MyDestImage2.png");
I have tried like this so cool..!!,
public void ThumbGenerate(string sourcepath,string thumbsavepath, int width, int height)
{
Image image = Image.FromFile(sourcepath);
Image thumb = image.GetThumbnailImage(width, height, () => false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(thumbsavepath, "jpg"));
}
Note :You can change extension what you like something jpg,jpeg,png
I am trying to draw some txt using method as in the PlayN Showcase app:
protected static Layer createTextLayer(TextLayout layout, int color) {
CanvasImage image = graphics().createImage((int) Math.ceil(layout.width()), (int) Math.ceil(layout.height()));
image.canvas().setFillColor(color);
image.canvas().fillText(layout, 0, 0);
return graphics().createImageLayer(image);
}
It works fine for HTML/Canvas but not for HTML/Dom.
Try to use tripleplay (https://github.com/threerings/tripleplay). Maybe it will help.
Label label = new Label("MY LABEL");
Interface iface = new Interface();
Stylesheet rootSheet = Stylesheet.builder().create();
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.add(label);
nameroot.setSize(100, 30);
nameroot.setStyles(Styles.make(Style.HALIGN.left));
PlayN.graphics().rootLayer().add(nameroot.layer);
I am creating a little map app where you are given information, video and images regarding different campuses in a university.
I am using the customContent method to insert video player object into the infoWindow but when I do this it gets rid of my text content and becomes the only visible thing to the user.
How Can I work around this and have both text and video in the infoWindow?
Demo link
public function createMarker(latlng:LatLng, name:String, address:String, video:String):Marker
{
var marker:Marker=new Marker(latlng);
marker.addEventListener(MapMouseEvent.CLICK, function(e:MapMouseEvent):void
{
//marker.openInfoWindow(new InfoWindowOptions({contentHTML:html + moulVid}));
var infoWindow:InfoWindowOptions = new InfoWindowOptions();
infoWindow.title = name;
var videoPlayer:VideoPlayer = new VideoPlayer();
videoPlayer.source = '../assets/video/' + video.toLocaleLowerCase();
videoPlayer.autoPlay = false;
videoPlayer.alpha = 0.8;
titleFormat = new TextFormat();
titleFormat.font = "Arial";
titleFormat.size = 14;
titleFormat.bold = true;
contentFormat = new TextFormat();
contentFormat.font = "Arial";
contentFormat.size = 12;
infoWindow.drawDefaultFrame = true;
infoWindow.titleFormat = titleFormat;
if (video != "") {
infoWindow.customContent = videoPlayer;
infoWindow.height = 300;
}
infoWindow.width = 380;
infoWindow.content = address;
infoWindow.contentFormat = contentFormat;
infoWindow.padding = 10;
marker.openInfoWindow(infoWindow);
});
You need to create a new object, called it like VideoAndTextInfoWindow, make it extend DisplayObject. Now in that component's constructor create and add a VideoPlayer and a TextField. This component may just publicly expose a videoSource and a text property. Create setters for those properties so that they set the correct properties on the VideoPlayer and TextField instances. Now set the infoWindow.customContent to a new instance of your VideoAndTextInfoWindow component.