public static async Task selectPic(Windows.UI.Xaml.Controls.Image pic) { var fop = new FileOpenPicker(); fop.ViewMode = PickerViewMode.Thumbnail; fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary; fop.FileTypeFilter.Add(".jpg"); fop.FileTypeFilter.Add(".jpeg"); fop.FileTypeFilter.Add(".png"); fop.FileTypeFilter.Add(".gif"); StorageFile file = await fop.PickSingleFileAsync(); try { IRandomAccessStream fileStream; using (fileStream = await file.OpenAsync(FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); pic.Source = bitmapImage; var name = file.Path.Substring(file.Path.LastIndexOf('\\') + 1); selectName = name; await file.CopyAsync(ApplicationData.Current.LocalFolder, name, NameCollisionOption.ReplaceExisting); } } catch (Exception e) { Debug.WriteLine(e.Message); return; } }
public BoxBackground(Color color, Color borderColor, double x = 0, double y = 0, double z = 10, double sizeX = 10, double sizeY = 10, Windows.UI.Xaml.Controls.Image img = null, double angle = 0) : base(x, y, z, sizeX, sizeY, 0) { // Default ? Color = color; BorderColor = borderColor; Image = img; }
public void Image_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Windows.UI.Xaml.Controls.Image img = sender as Windows.UI.Xaml.Controls.Image; if (img != null) { img.Source = new BitmapImage(CurrentBenefitCollection[0].BenefitImage); } Debug.WriteLine("Load"); }
public async Task <byte[]> GetImage() { Windows.UI.Xaml.Controls.Image image = new Windows.UI.Xaml.Controls.Image(); Uri url = new Uri("ms-appx:///Assets/ImageJPG.jpg"); WriteableBitmap bitmapImage = new WriteableBitmap(1, 1); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(url); using (var stream = await storageFile.OpenReadAsync()) { await bitmapImage.SetSourceAsync(stream); } return(await bitmapImage.ToByteArrayAsync(DevKit.Xamarin.ImageKit.Abstractions.ImageFormat.JPG, 100)); }
private async void SetImageAsync(ImageSource source) { if (source != null) { var handler = GetHandler(source); var imageSource = await handler.LoadImageAsync(source); if (imageSource != null) { Windows.UI.Xaml.Controls.Image image = new Windows.UI.Xaml.Controls.Image(); image.Source = imageSource; this.Control.Content = image; } } }
/* * This method takes an ElementChangedEventArgs parameter that contains OldElement and NewElement properties. * These properties represent the Xamarin.Forms element that the renderer was attached to, * and the Xamarin.Forms element that the renderer is attached to, respectively. * In the sample application the OldElement property will be null * and the NewElement property will contain a reference to the CameraPage instance. */ protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); Debug.Write(e.OldElement == null); Debug.Write(e.NewElement == null); if (e.OldElement != null || Element == null) { return; } Windows.UI.Xaml.Controls.Image image = new Windows.UI.Xaml.Controls.Image() { Width = 100, Height = 100, HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left }; BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appx://XamarinCustomContentPage.UWP/Assets/picture.png")); image.Source = bitmapImage; sta = new Windows.UI.Xaml.Controls.StackPanel(); bt = new Windows.UI.Xaml.Controls.Button(); bt.Content = "hello , my custom page"; bt.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(25, 0, 0, 255)); bt.Click += OnClicked; sta.Children.Add(image); sta.Children.Add(bt); //instantiate a page page = new Windows.UI.Xaml.Controls.Page(); //add content to a page page.Content = sta; //put this page to this custom render as a children //must add content to the renderer,the content can be a stackpanel or the page or the image //a control only can be add into a contain control such as,if the image control add to the stackpanel , //it can not be added to page.content or this render.content this.Children.Add(page); }
/// <summary> /// Cache printable output /// </summary> /// <param name="p">Number of first page to print</param> /// <param name="count">Number of pages to print</param> /// <returns>Task that the caller is expected to await</returns> private async Task PrepareForPrintAsync(int p, int count /*, StorageFolder tempfolder*/) { if ((_pageImages is null) || (_pageImages.Count == 0)) { ClearCachedPages(); _pageImages = new List <Windows.UI.Xaml.Controls.Image>(); _ = new Windows.UI.Xaml.Controls.Image(); for (int i = p; i < count; i++) { ApplicationLanguages.PrimaryLanguageOverride = CultureInfo.InvariantCulture.TwoLetterISOLanguageName; Windows.Data.Pdf.PdfPage pdfPage = _pdfDocument.GetPage(uint.Parse(i.ToString())); double pdfPagePreferredZoom = pdfPage.PreferredZoom; IRandomAccessStream randomStream = new InMemoryRandomAccessStream(); global::Windows.Data.Pdf.PdfPageRenderOptions pdfPageRenderOptions = new global::Windows.Data.Pdf.PdfPageRenderOptions(); Windows.Foundation.Size pdfPageSize = pdfPage.Size; pdfPageRenderOptions.DestinationHeight = (uint)(pdfPageSize.Height * pdfPagePreferredZoom); pdfPageRenderOptions.DestinationWidth = (uint)(pdfPageSize.Width * pdfPagePreferredZoom); await pdfPage.RenderToStreamAsync(randomStream, pdfPageRenderOptions); Windows.UI.Xaml.Controls.Image imageCtrl = new Windows.UI.Xaml.Controls.Image(); BitmapImage src = new BitmapImage(); randomStream.Seek(0); src.SetSource(randomStream); imageCtrl.Source = src; Windows.Graphics.Display.DisplayInformation DisplayInformation = Windows.Graphics.Display.DisplayInformation.GetForCurrentView(); float dpi = DisplayInformation.LogicalDpi / 96; imageCtrl.Height = src.PixelHeight / dpi; imageCtrl.Width = src.PixelWidth / dpi; randomStream.Dispose(); pdfPage.Dispose(); _pageImages.Add(imageCtrl); AddPageToCache(imageCtrl); } } }
public async Task PrintAsync(string file) { #region 印刷の準備 _printDocument = new PrintDocument(); _printDocumentSource = _printDocument.DocumentSource; _printDocument.Paginate += CreatePrintPreviewPages; _printDocument.GetPreviewPage += GetPreviewPage; _printDocument.AddPages += AddPages; var printManager = PrintManager.GetForCurrentView(); printManager.PrintTaskRequested += PrintTaskRequested; #endregion try { #region PDF情報 取得 var storage = ApplicationData.Current.LocalFolder; var path = await storage.GetFileAsync(file); var pdfDocument = await PdfDocument.LoadFromFileAsync(path); #endregion _imageList = new UListView(); #region 印刷情報 取得 try { for (int i = 0; i < pdfDocument.PageCount; i++) { using (var page = pdfDocument.GetPage((uint)i)) { var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); await page.RenderToStreamAsync(stream); // BitmapImage 作成 var src = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); var image = new UImage(); image.Source = src; // BitmapImageをsrcにセット await src.SetSourceAsync(stream); _imageList.Items.Add(image); } } } finally { pdfDocument = null; } #endregion if (PrintManager.IsSupported()) { // 印刷ダイアログ表示 await PrintManager.ShowPrintUIAsync(); } } finally { // プリンターとの接続切断 printManager.PrintTaskRequested -= PrintTaskRequested; } }
public static void Init(GlobalState state) { _state = state; //if (state != null && state.IsSharpDxRendering) //{ // BaseRenderer.UpdateState((BaseRenderer)BackgroundRenderer, state); // BaseRenderer.UpdateState((BaseRenderer)MagicRenderer, state); //} if (IsInitialized) { return; } //if (state.IsSharpDxRendering) //{ // _deviceManager1 = new CommonDX.DeviceManager(); // _deviceManager2 = new CommonDX.DeviceManager(); // _renderer1 = new DxRenderer.BackgroundComposer() { State = _state }; // _renderer2 = new DxRenderer.MagicComposer() { State = _state }; // BackgroundSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer1.Update(gt); }, // (tb) => { _renderer1.Render(tb); }, // (dm) => { _renderer1.Initialize(dm); }, // (e1, e2) => { _renderer1.InitializeUI(e1, e2); }, // (uri) => { _renderer1.LoadLocalAsset(uri); }, // () => { _renderer1.Unload(); }, // _deviceManager1); // //_renderer1, _deviceManager1); // MagicSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer2.Update(gt); }, // (tb) => { _renderer2.Render(tb); }, // (dm) => { _renderer2.Initialize(dm); }, // (e1, e2) => { _renderer2.InitializeUI(e1, e2); }, // (uri) => { _renderer2.LoadLocalAsset(uri); }, // () => { _renderer2.Unload(); }, // _deviceManager2); // //_renderer2, _deviceManager2); //} //else //{ //FALLBACK TO IMAGE/WRITEABLEBITMAP RENDERING BackgroundBitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); BackgroundBitmapImage.UriSource = new Uri(_state.DefaultBackgroundUri); BackgroundImage = new Windows.UI.Xaml.Controls.Image(); BackgroundImage.Source = BackgroundBitmapImage; BackgroundImage.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill; BackgroundImage.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; BackgroundImage.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //FALLBACK TO XAML EXPLOSIONS ExplosionSurface = new SumoNinjaMonkey.Framework.Controls.Explosions.DrawingSurface(); ExplosionSurface.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; ExplosionSurface.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //} IsInitialized = true; }
public static void Unload() { Stop(); //if (_state.IsSharpDxRendering) //{ // if (BackgroundSIS != null) // { // BackgroundSIS.Unload(); // BackgroundSIS = null; // } // if (MagicSIS != null) // { // MagicSIS.Unload(); // MagicSIS = null; // } // if (_renderer1 != null) // { // _renderer1.Unload(); // _renderer1 = null; // } // if (_renderer2 != null) // { // _renderer2.Unload(); // _renderer2 = null; // } // if (_deviceManager1 != null) // { // _deviceManager1.Dispose(); // _deviceManager1 = null; // } // if (_deviceManager2 != null) // { // _deviceManager2.Dispose(); // _deviceManager2 = null; // } //} //else //{ //FALLBACK TO IMAGE/WRITEABLEBITMAP RENDERING BackgroundImage.Source = null; BackgroundImage = null; BackgroundBitmapImage = null; ExplosionSurface = null; //} IsInitialized = false; //need to do the disposing of the dx surfaces and pipeline here! }
protected async override void OnElementChanged(ElementChangedEventArgs <ImageButton> e) { base.OnElementChanged(e); if (e.NewElement != null) { if (Control == null) { _formsButton = new FormsButton(); _formsButton.Padding = new WThickness(0); _formsButton.BorderThickness = new WThickness(0); _formsButton.Background = null; _image = new Windows.UI.Xaml.Controls.Image() { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Stretch = Stretch.Uniform, }; _image.ImageOpened += OnImageOpened; _image.ImageFailed += OnImageFailed; _formsButton.Content = _image; _formsButton.Click += OnButtonClick; _formsButton.AddHandler(PointerPressedEvent, new PointerEventHandler(OnPointerPressed), true); _formsButton.Loaded += ButtonOnLoaded; SetNativeControl(_formsButton); } else { WireUpFormsVsm(); } //TODO: We may want to revisit this strategy later. If a user wants to reset any of these to the default, the UI won't update. if (Element.IsSet(VisualElement.BackgroundColorProperty) && Element.BackgroundColor != (Color)VisualElement.BackgroundColorProperty.DefaultValue) { UpdateBackground(); } if (Element.IsSet(ImageButton.BorderColorProperty) && Element.BorderColor != (Color)ImageButton.BorderColorProperty.DefaultValue) { UpdateBorderColor(); } if (Element.IsSet(ImageButton.BorderWidthProperty) && Element.BorderWidth != (double)ImageButton.BorderWidthProperty.DefaultValue) { UpdateBorderWidth(); } if (Element.IsSet(ImageButton.CornerRadiusProperty) && Element.CornerRadius != (int)ImageButton.CornerRadiusProperty.DefaultValue) { UpdateBorderRadius(); } // By default Button loads width padding 8, 4, 8 ,4 if (Element.IsSet(Button.PaddingProperty)) { UpdatePadding(); } await TryUpdateSource().ConfigureAwait(false); } }
public static void Init(GlobalState state) { _state = state; //if (state != null && state.IsSharpDxRendering) //{ // BaseRenderer.UpdateState((BaseRenderer)BackgroundRenderer, state); // BaseRenderer.UpdateState((BaseRenderer)MagicRenderer, state); //} if (IsInitialized) return; //if (state.IsSharpDxRendering) //{ // _deviceManager1 = new CommonDX.DeviceManager(); // _deviceManager2 = new CommonDX.DeviceManager(); // _renderer1 = new DxRenderer.BackgroundComposer() { State = _state }; // _renderer2 = new DxRenderer.MagicComposer() { State = _state }; // BackgroundSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer1.Update(gt); }, // (tb) => { _renderer1.Render(tb); }, // (dm) => { _renderer1.Initialize(dm); }, // (e1, e2) => { _renderer1.InitializeUI(e1, e2); }, // (uri) => { _renderer1.LoadLocalAsset(uri); }, // () => { _renderer1.Unload(); }, // _deviceManager1); // //_renderer1, _deviceManager1); // MagicSIS = new SumoNinjaMonkey.Framework.Controls.DrawingSurfaceSIS( // (gt) => { _renderer2.Update(gt); }, // (tb) => { _renderer2.Render(tb); }, // (dm) => { _renderer2.Initialize(dm); }, // (e1, e2) => { _renderer2.InitializeUI(e1, e2); }, // (uri) => { _renderer2.LoadLocalAsset(uri); }, // () => { _renderer2.Unload(); }, // _deviceManager2); // //_renderer2, _deviceManager2); //} //else //{ //FALLBACK TO IMAGE/WRITEABLEBITMAP RENDERING BackgroundBitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); BackgroundBitmapImage.UriSource = new Uri(_state.DefaultBackgroundUri); BackgroundImage = new Windows.UI.Xaml.Controls.Image(); BackgroundImage.Source = BackgroundBitmapImage; BackgroundImage.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill; BackgroundImage.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; BackgroundImage.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //FALLBACK TO XAML EXPLOSIONS ExplosionSurface = new SumoNinjaMonkey.Framework.Controls.Explosions.DrawingSurface(); ExplosionSurface.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch; ExplosionSurface.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch; //} IsInitialized = true; }
public void RegisterAll() { if (!Config.Instance.RegisterSetAds) return; var ads = Config.Instance.Ad; var adParent = ads.AdHolder; AdControlSmall = new AdControl(ads.AdApplicationId, ads.SmallAdUnitId, true) { Width = 300, Height = 50, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; AdControlSmall.ErrorOccurred += AdControlSmall_ErrorOccurred; AdControlSmall.AdRefreshed += AdControlSmall_Refreshed; AdControlSmall.Loaded += AdControlSmall_Loaded; AdControlMedium = new AdControl(ads.AdApplicationId, ads.MediumAdUnitId, true) { Width = 480, Height = 80, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; AdControlMedium.ErrorOccurred += AdControlMedium_ErrorOccurred; AdControlMedium.AdRefreshed += AdControlMedium_Refreshed; AdControlMedium.Loaded += AdControlMedium_Loaded; AdControlLarge = new AdControl(ads.AdApplicationId, ads.LargeAdUnitId, true) { Width = 640, Height = 100, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; AdControlLarge.ErrorOccurred += AdControlLarge_ErrorOccurred; AdControlLarge.AdRefreshed += AdControlLarge_Refreshed; AdControlLarge.Loaded += AdControlLarge_Loaded; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri("ms-appx:///Core/Assets/banner_Jens_Dennis.png"); ProgPartyBanner = new Img() { Source = bitmapImage, Width = 480, Height = 80, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; ProgPartyBanner.PointerReleased += ProgPartyBanner_PointerReleased; adParent.Children.Add(AdControlSmall); adParent.Children.Add(AdControlMedium); adParent.Children.Add(AdControlLarge); adParent.Children.Add(ProgPartyBanner); }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement, Jupiter.Controls.Image image) { var rect = image.GetBoundingRect(rootElement).ToSharpDX(); if (rect.Width == 0 || rect.Height == 0) { return; } var bitmap = await image.Source.ToSharpDX(renderTarget); if (bitmap == null) { return; } try { //var layer = new Layer(renderTarget); //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); renderTarget.DrawBitmap( bitmap, rect, (float)image.Opacity, D2D.BitmapInterpolationMode.Linear); //renderTarget.PopLayer(); } finally { bitmap.Dispose(); } }
public GesturePage() : base( "SemanticZoom", "Pinch to semantic zoom", "Semantic zoom is a new concept in our touch language. It’s designed to make it fast and fluid to jump within a list of content. Pinch two or more fingers on the screen to change to an overview view. Then tap or stretch the region or item you want to see more details for. For example, in People, pinch your contact list to see alphabet tiles (A, B, etc.), and then tap the desired letter to get back to the individual contact level (J for Jan).", "Similar to when you use a mouse and click the “-” button, usually found in the lower-right corner.", "Assets/pinch_sezo.png") { // Configure the app bar items for this page // GesturePageBase.Selected uses this._nonContextualItems to populate the global app bar when the page is selected. // Links button this._links["Doc: Guidelines for semantic zoom"] = new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/hh465319.aspx"); this._nonContextualItems.Add(GesturePageBase.CreateLinksAppBarButton(this._links)); // Create the play area for this page var grid = new Windows.UI.Xaml.Controls.Grid(); var row = new Windows.UI.Xaml.Controls.RowDefinition(); row.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star); grid.RowDefinitions.Add(row); row = new Windows.UI.Xaml.Controls.RowDefinition(); row.Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Auto); grid.RowDefinitions.Add(row); var col = new Windows.UI.Xaml.Controls.ColumnDefinition(); col.Width = new Windows.UI.Xaml.GridLength(2, Windows.UI.Xaml.GridUnitType.Star); grid.ColumnDefinitions.Add(col); col = new Windows.UI.Xaml.Controls.ColumnDefinition(); col.Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star); grid.ColumnDefinitions.Add(col); var image = new Windows.UI.Xaml.Controls.Image { Margin = new Windows.UI.Xaml.Thickness(30, 30, 30, 30), Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appx:///Assets/semantic_zoom.png")), Stretch = Windows.UI.Xaml.Media.Stretch.Uniform }; grid.Children.Add(image); Windows.UI.Xaml.Controls.Grid.SetColumn(image, 0); Windows.UI.Xaml.Controls.Grid.SetRow(image, 0); var textBlock = new Windows.UI.Xaml.Controls.TextBlock { Style = App.Current.Resources["AppSubtitleTextStyle"] as Windows.UI.Xaml.Style, Text = "Pinch anywhere in this app to zoom out", HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center, TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap, TextAlignment = Windows.UI.Xaml.TextAlignment.Center }; grid.Children.Add(textBlock); Windows.UI.Xaml.Controls.Grid.SetColumn(textBlock, 1); Windows.UI.Xaml.Controls.Grid.SetRow(textBlock, 0); this.Content = grid; }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, Jupiter.FrameworkElement rootElement, Jupiter.Controls.Image image) { var rect = image.GetBoundingRect(rootElement).ToSharpDX(); if (rect.Width == 0 || rect.Height == 0) { return; } var bitmap = await image.Source.ToSharpDX(renderTarget); if (bitmap == null) { return; } try { var layer = image.CreateAndPushLayerIfNecessary(renderTarget, rootElement); renderTarget.DrawBitmap( bitmap, rect, (float)image.Opacity, D2D.BitmapInterpolationMode.Linear); if (layer != null) { renderTarget.PopLayer(); layer.Dispose(); } } finally { bitmap.Dispose(); } }
public BoxBackground(double x = 0, double y = 0, double z = 10, double sizeX = 10, double sizeY = 10, Windows.UI.Xaml.Controls.Image img = null, double angle = 0) : this(Colors.Transparent, Colors.Transparent, x, y, z, sizeX, sizeY, img, angle) { }
public void quedin() { Windows.UI.Xaml.Controls.Image image = xf.SelectedItem as Windows.UI.Xaml.Controls.Image; _m.writeasset桌面(image.Tag as Windows.Storage.StorageFile); }
public static extern void WinrtSetFrameContainer(Windows.UI.Xaml.Controls.Image image);