I have a resource item (a png file) in my resource dictionary which I'm using in several places. Now I want to use it as application's NotifyIcon. But I don't know how to do this. Have you any idea please?
// my image:
var bitmap = new BitmapImage();
bitmap.UriSource = new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png");
// and I try to do this:
var iconHandle = bitmap.GetHicon(); // but this line doesn't work
var ni = new NotifyIcon {
Icon = System.Drawing.Icon.FromHandle(iconHandle),
Visible = true
};
var sri = Application.GetResourceStream(
new Uri("pack://application:,,,/MyProj.Resources;component/Icons/Logo_48x48.png"));
var bitmap = new Bitmap(sri.Stream);
var handle = bitmap.GetHicon();
var ni = new NotifyIcon {
Icon = System.Drawing.Icon.FromHandle(handle),
Visible = true
};
Related
How can I set the hint 'AutoRotate' for 'GenericMultipleBarcodeReader' in Zxing.net. I have set Try_Harder = true. But no results for detecting multiple 1d/2d barcodes from a rotated image. If the image is aligned properly it gives the results.
Edit: In 'GenericMultipleBarcodeReader' I am using 'ByQuadrantReader'. This could detect barcodes and QR codes from properly aligned images. For a rotated image it could not find anything.
MultiFormatReader multiReader = new MultiFormatReader();
ZXing.Multi.GenericMultipleBarcodeReader byquadReader = new ZXing.Multi.GenericMultipleBarcodeReader(new ByQuadrantReader(multiReader));
Dictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType, object>();
hints.Add(DecodeHintType.TRY_HARDER, true);
List<BarcodeFormat> formats = new List<BarcodeFormat>();
formats.Add(BarcodeFormat.All_1D);
formats.Add(BarcodeFormat.QR_CODE);
hints.Add(DecodeHintType.POSSIBLE_FORMATS, formats);
****
byquadresults = byquadReader.decodeMultiple(binaryBitmap, hints);
Could any one please help me.
AutoRotate can only be used with the BarcodeReader class.
var bitmap = (Bitmap)Bitmap.FromFile("<path to your image file>");
var reader = new BarcodeReader
{
AutoRotate = true,
Options = new DecodingOptions
{
TryHarder = true,
PossibleFormats = new List<BarcodeFormat>
{
BarcodeFormat.All_1D,
BarcodeFormat.QR_CODE
}
}
};
var results = reader.DecodeMultiple(bitmap);
If you want to use the ByQuadrantReader you have to replace the line
var reader = new BarcodeReader...
with
var reader = new BarcodeReader(new ByQuadrantReader(new MultiFormatReader()), null, null)...
I am a beginner in Windows Phone development, while trying to develop a map based application, I am stuck how to add a MapIcon or any MapChildren for a no. of locations stored in a database file.
I have successfully retrieved the data collection from the database, further i don't know how to add a mapIcon for each entry
try
{
double latitude = myposition.Coordinate.Point.Position.Latitude;
double longitude = myposition.Coordinate.Point.Position.Longitude;
Collection bins = new Collection(); //collection of class Dustbin
bins = DustbinViewModel.GetDefault().GetItem(latitude, longitude); //database query using ViewModels..It is working
msgbox = new MessageDialog("Dustbins retrieved");
await msgbox.ShowAsync();
string msg = "";
foreach (Dustbin d in bins)
{
msg = msg + d.Id + "\n";
}
msgbox = new MessageDialog(msg); //Just for checking whether the data is recieved or not
await msgbox.ShowAsync();
int i = 1;
foreach (Dustbin d in bins)
{
Geopoint point = new Geopoint(new BasicGeoposition
{
Latitude = d.Latitude,
Longitude = d.Latitude
});
/*var shape = new MapIcon
{
Title = "Dustbin:" + i,
Location = point,
Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/dustbin.png")),
NormalizedAnchorPoint = new Point(0.5, 0.5),
ZIndex = 5,
};
MyMap.MapElements.Add(shape);*/
Image image = new Image();
image.Width = 40;
image.Height = 40;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("ms-appx:///Assets/location.png");
image.Source = bitmapImage;
MapControl.SetLocation(image, point);
MapControl.SetNormalizedAnchorPoint(image, new Point(0.25, 0.9));
MyMap.Children.Add(image);
i++;
}
}
catch(Exception ex)
{
msgbox = new MessageDialog("Something went wrong !! Please try again later."+ex.Message);
await msgbox.ShowAsync();
}
As I am new to this field, I will be thankful to your answers..
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri("ms-appx:///Assets/location.png");
image.Source = bitmapImage;
MapControl.SetLocation(image, point);
MapControl.SetNormalizedAnchorPoint(image, new Point(0.25, 0.9));
MyMap.Children.Add(image);
Just add
MapControl.SetLocation(bitmapImage, point);
MyMap.Children.Add(bitmapImage);
MapControl.SetNormalizedAnchorPoint(bitmapImage, new Point(0.25, 0.9));
I was wondering if there was a way to crop videos in Xamarin. I can't seem to find any examples. I tried looking at the existing functions and Classes but I couldn't find anything.
Basically make square videos like what Vine and Instagram have. I think this is done by cropping out the rest of the video and not just zooming in.
I find part of the code from one source, I tried to add owner but I could not find. The solution's key part is added by me for cropping which is "VideoCleanAperture" inside AVVideoSettingsCompressed.
videoUrl = ((AVFoundation.AVUrlAsset)avAsset).Url;
NSError assetReaderError;
var assetReader = AVAssetReader.FromAsset(avAsset, out assetReaderError);
var assetTrack = avAsset.Tracks.First();
//Height = (System.nint?)avAsset.NaturalSize.Height,
//Width = (System.nint?)avAsset.NaturalSize.Width,
var inputSettings = new AVVideoSettingsUncompressed()
{
Height = (System.nint?)avAsset.NaturalSize.Height,
Width = (System.nint?)avAsset.NaturalSize.Width,
};
var assetReaderOutput = new AVAssetReaderTrackOutput(assetTrack, settings: inputSettings);
assetReaderOutput.AlwaysCopiesSampleData = false;
string tempFile = Path.Combine(Path.GetTempPath(), "CroppedVideo.mp4");
if (File.Exists(tempFile)) File.Delete(tempFile);
var url = NSUrl.FromFilename(tempFile);
NSError assetWriterError;
var assetWriter = new AVAssetWriter(url, AVFileType.Mpeg4, out assetWriterError);
var outputSettings = new AVVideoSettingsCompressed()
{
Height = 300,
Width = 300,
Codec = AVVideoCodec.H264,
CodecSettings = new AVVideoCodecSettings()
{
AverageBitRate = 1000000,
VideoCleanAperture = new AVVideoCleanApertureSettings(
new NSDictionary(
AVVideo.CleanApertureWidthKey, new NSNumber(300),
AVVideo.CleanApertureHeightKey, new NSNumber(300),
AVVideo.CleanApertureVerticalOffsetKey, new NSNumber(10),
AVVideo.CleanApertureHorizontalOffsetKey, new NSNumber(10)
)
)
},
ScalingMode = AVVideoScalingMode.ResizeAspectFill
};
var assetWriterInput = new AVAssetWriterInput(mediaType: AVMediaType.Video, outputSettings: outputSettings);
assetWriterInput.ExpectsMediaDataInRealTime = false;
assetWriter.AddInput(assetWriterInput);
assetWriter.StartWriting();
assetReader.AddOutput(assetReaderOutput);
assetReader.StartReading();
assetWriter.StartSessionAtSourceTime(CoreMedia.CMTime.Zero);
var mediaInputQueue = new DispatchQueue("mediaInputQueue");
assetWriterInput.RequestMediaData(mediaInputQueue, () =>
{
while (assetWriterInput.ReadyForMoreMediaData)
{
var nextBuffer = assetReaderOutput.CopyNextSampleBuffer();
if (nextBuffer != null)
{
assetWriterInput.AppendSampleBuffer(nextBuffer);
}
else
{
assetWriterInput.MarkAsFinished();
assetWriter.FinishWritingAsync();
assetReader.CancelReading();
assetReader.Dispose();
assetReaderOutput.Dispose();
assetWriter.Dispose();
assetWriterInput.Dispose();
break;
}
}
});
}
I might be missing something here, but this code:
this.oSectionDRs = new Section()
{
new ActivityElement()
{
Caption = Locale.GetLocale("Settings_Loading"),
Animating = true
}
};
// To begin with just show a loading indicator.
this.Root = new RootElement (Locale.GetLocale("Settings_Select"))
{
this.oSectionDRs
};
Does not show any animated thingy. It is showing the label only. How can I get the animated star?
Using this code:
var root = new RootElement("foo");
root.Add (new Section("foo", "bar") {
new ActivityElement()
{
Caption = "foo",
Animating = true
}
});
var dvc = new DialogViewController(root, false);
window.RootViewController = dvc;
I get both the caption and the activity scroller thing. Not sure it helps you tho! I was just using the built in MT.D.
I've made a application that uses live tiles. I get it to work with the backgroundtask, it shows correct message but the image is completely black...
Here is my code where I save the image to /Shared/ShellContent/:
public MainPage()
{
InitializeComponent();
CurrentPlaceList = new ObservableCollection<CurrentPlaceListItemModel>();
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
var bmp = new WriteableBitmap(173, 173);
var weatherImage = new BitmapImage(new Uri("/Images/WeatherIcons/01d.png", UriKind.Relative));
var img = new Image { Source = weatherImage };
weatherImage.CreateOptions = BitmapCreateOptions.None;
var tt = new TranslateTransform();
tt.X = 0;
tt.Y = 0;
bmp.Render(img, tt);
bmp.Invalidate();
var filename = "/Shared/ShellContent/01d.jpg";
using (var st = new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, store))
{
bmp.SaveJpeg(st, 173, 173, 0, 100);
}
}
StartAgent();
}
And where is my code where my ScheduledTask is supposed to update text and image, the images is completely black :(
protected override void OnInvoke(ScheduledTask task)
{
//TODO: Add code to perform your task in background
UpdateAppTile("-99");
NotifyComplete();
}
private void UpdateAppTile(string message)
{
ShellTile appTile = ShellTile.ActiveTiles.FirstOrDefault();
if (appTile != null)
{
StandardTileData tileData = new StandardTileData
{
Title = message,
BackgroundImage = new System.Uri("isostore:/Shared/ShellContent/01d.jpg", System.UriKind.Absolute)
};
appTile.Update(tileData);
}
}
This is taken from several tutorials, could anyone put a finger on what is wrong?
For me it looks like the image doesn't have enough time to load. I think the better way here is to do something like:
StreamResourceInfo streamImage = Application.GetResourceStream(uri.Uri);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(streamImage.Stream);
Image image = new Image() { Width = uri.Width, Height = uri.Height, Source = bitmapImage };
Also, you can check out a MSP Toolkit that could generate tile for you (msptoolkit on NuGet).