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).
Related
Hi everyone I'm trying to change 'System.Drawing.Image' to 'System.Drawing.Image[] to use at my code so How To make it works as I need to merge tiff image to exist Multi Tif image thanks.
and If I need to add pages to exist Multi tif image after select page how to do that? and if there another way to do that please help me?
Image img2 = Image.FromFile(imagename1);
Image img = Image.FromFile(imagename2);
Tiff.TiffUtil.saveImageExistingMultiplePage(img2, img, 2,
imagename2);
public static void saveImageExistingMultiplePage(Image[] bmp, Image origionalFile, int PageNumber, string location)
{
try
{
//Now load the Codecs
ImageCodecInfo codecInfo = getCodec();
System.Drawing.Imaging.Encoder saveEncoder;
System.Drawing.Imaging.Encoder compressionEncoder;
EncoderParameter saveEncodeParam;
EncoderParameter compressionEncodeParam;
EncoderParameters encoderParams = new EncoderParameters(2);
Bitmap pages;
Bitmap nextPage;
saveEncoder = System.Drawing.Imaging.Encoder.SaveFlag;
compressionEncoder = System.Drawing.Imaging.Encoder.Compression;
origionalFile.SelectActiveFrame(FrameDimension.Page, 0);
pages = new Bitmap(origionalFile);
pages = ConvertToBitonal(pages);
// Save the first page (frame).
saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.MultiFrame);
compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = compressionEncodeParam;
encoderParams.Param[1] = saveEncodeParam;
pages.Save(location, codecInfo, encoderParams);
for (int i = 1; i < PageNumber; i++)
{
saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.FrameDimensionPage);
compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = compressionEncodeParam;
encoderParams.Param[1] = saveEncodeParam;
origionalFile.SelectActiveFrame(FrameDimension.Page, i);
nextPage = new Bitmap(origionalFile);
nextPage = ConvertToBitonal(nextPage);
pages.SaveAdd(nextPage, encoderParams);
}
for (int i = 0; i < bmp.Length; i++)
{
saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.FrameDimensionPage);
compressionEncodeParam = new EncoderParameter(compressionEncoder, (long)EncoderValue.CompressionCCITT4);
encoderParams.Param[0] = compressionEncodeParam;
encoderParams.Param[1] = saveEncodeParam;
bmp[i] = (Bitmap)ConvertToBitonal((Bitmap)bmp[i]);
pages.SaveAdd(bmp[i], encoderParams);
}
saveEncodeParam = new EncoderParameter(saveEncoder, (long)EncoderValue.Flush);
encoderParams.Param[0] = saveEncodeParam;
pages.SaveAdd(encoderParams);
}
catch (System.Exception ee)
{
throw ee;
}
}
// initialize an image array and add your image to it
Image[] img2 = new Image[] { Image.FromFile(imagename1) };
// the rest of your code stays the same but 'img2' is now an array of images
// so the call to 'saveImageExistingMultiplePage' will accept it.
// ...
Tiff.TiffUtil.saveImageExistingMultiplePage(img2, img, 2, imagename2);
// ... continue your code
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 have a project using aforge.net, and i kind of facing a problem.
i always got Invalid image size specified exception, and i don't know why.
if anybody could help me, it would be great...
here's my code:
private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
{
string filepath = #"C:\Users\user\Documents\Visual Studio 2010\Projects\plat.JPG";
Bitmap imageContoh = new Bitmap(System.Drawing.Image.FromFile(filepath, true));
UnmanagedImage unImage = UnmanagedImage.FromManagedImage(imageContoh);
UnmanagedImage clone = unImage.Clone();
ResizeBilinear resize = new ResizeBilinear(512, 512);
imageUntukDiproses = resize.Apply(clone);
if (imageUntukDiproses != null)
{
//Preprosessing gambar
PreProcessing pre = new PreProcessing(imageUntukDiproses);
UnmanagedImage hasilPre = pre.HasilPreProcessing;
UnmanagedImage grayscale = pre.GambarGrayscale;
//penentuan lokasi plat
PenentuLokasiPlat plat = new PenentuLokasiPlat(hasilPre, grayscale);
//ekstraksi plat
UnmanagedImage platfix = plat.PlatKendaraan;
plat.Drawing(image);
//tampilan histogram untuk hasil preprosessing
histogram1.Values = plat.Hishorlogic;
histogram3.Values = plat.Hisverlogic;
if (platfix != null)
{
SegmentasiHuruf segmen = new SegmentasiHuruf(platfix);
byte[,] ciripertama = segmen.Karakter[1];
this.Invoke(new MethodInvoker(delegate() { dataGridView1.DataSource = new ArrayDataView(ciripertama); }));
//Menampilkan image hasil
}
}
Bitmap gambar = imageUntukDiproses.ToManagedImage();
image = gambar;
}
on the exception i see image is null..
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
};