Esempio n. 1
0
        //Point? mp = null;
        //private void resizeHandle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    mp = e.GetPosition((UIElement)sender);
        //    ((UIElement)sender).CaptureMouse();
        //}
        //private void resizeHandle_MouseMove(object sender, MouseEventArgs e)
        //{
        //    if (mp != null)
        //    {
        //    }
        //}
        //private void resizeHandle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        //{
        //    mp = null;
        //    ((Canvas)sender).ReleaseMouseCapture();
        //}
        private void LayoutRoot_Drop(object sender, DragEventArgs e)
        {
            var file = ((FileInfo[])e.Data.GetData(DataFormats.FileDrop))[0];
            string fn = file.Name.ToLower();
            WriteableBitmap wb = null;
            if (fn.EndsWith(".jpg") || fn.EndsWith(".png"))
            {
                BitmapImage bi = new BitmapImage();
                try
                {
                    bi.SetSource(file.OpenRead());
                    if (bi.PixelWidth < 50 || bi.PixelHeight < 50)
                    {
                        MessageBox.Show("画像サイズが小さすぎます");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("エラー");
                    return;
                }
                wb = new WriteableBitmap(bi);

            }
            else if (fn.EndsWith(".bmp"))
            {
                IImageDecoder dec = new BmpDecoder();
                FileStream fs = file.OpenRead();
                ImageTools.Image img = new ImageTools.Image();
                try
                {
                    dec.Decode(img, fs);
                }
                catch
                {
                    MessageBox.Show("エラー");
                    return;
                }
                if (img.Width < 50 || img.Height < 50)
                {
                    MessageBox.Show("画像サイズが小さすぎます");
                    return;
                }
                wb = new WriteableBitmap(img.Width, img.Height);
                byte[] data = img.GetPixels();
                for (int y = 0; y < img.Height; y++)
                {
                    for (int x = 0; x < img.Width; x++)
                    {
                        int idx = (x + y * img.Width) * 4;
                        wb.SetPixel(x, y, Color.FromArgb(data[idx + 3], data[idx], data[idx + 1], data[idx + 2]));
                    }
                }
                fs.Close();
            }
            else
            {
                MessageBox.Show("エラー");
                return;
            }
            try
            {
                SetImage(wb);
            }
            catch
            {
                MessageBox.Show("エラー");
            }
        }
        private void DownloadUserImage(string host, LocomotiveImage img)
        {
            if (!string.IsNullOrEmpty(img.Url))
            {
                WebClient webClient = new WebClient();
                webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
                {
                    if (e.Error != null)
                        Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show(e.Error.Message, App.Name, MessageBoxButton.OK); });
                    else
                    {
                        int imageIdx = (int)e.UserState;

                        ExtendedImage eimg = new ExtendedImage();
                        var bd = new BmpDecoder();
                        //var bd = new PngDecoder();
                        //var bd = new JpegDecoder();
                        //var bd = new GifDecoder();
                        bd.Decode(eimg, e.Result);
                        //MemoryStream ms = (MemoryStream)eimg.ToStreamByExtension("bmp");

                        //BitmapImage bi = new BitmapImage();
                        //bi.SetSource(ms);

                        //App.EcosModel.LocomotivesManager.ItemsUser[imageIdx].BitmapImage = bi;

                        e.Result.Close();
                    }
                };

                webClient.OpenReadAsync(new Uri(host + img.Url, UriKind.Absolute), img.Index);
            }
        }
Esempio n. 3
0
        private void ViewCurrentImageButton_Click(object sender, RoutedEventArgs e)
        {
            GoogleAnalytics.EasyTracker.GetTracker().SendEvent("splashchanger", "click", "View Current Image", 0);
            try
            {
            #if WP8
                CustomMessageBox cmb = new CustomMessageBox()
                {
                    IsLeftButtonEnabled = true,
                    IsRightButtonEnabled = true,
                    RightButtonContent = "Shutdown",
                    LeftButtonContent = "Startup",
                    Message = "Which boot screen you'd like to view?"

                };
                cmb.Dismissed += new EventHandler<DismissedEventArgs>((dsender, de) =>
                {
                    string screen = "Boot";
                    if (de.Result == CustomMessageBoxResult.RightButton)
                    {
                        screen = "Shutdown";
                    }
                    try {
                    using (var stream = System.IO.File.OpenRead(Registry.ReadString(RegistryHive.HKLM, @"SYSTEM\Shell\BootScreens", "WP" + screen + "ScreenOverride")))
                    {
            #else

                using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!store.FileExists("mologo.bmp"))
                    {

                        string dir = @"\Applications\Data\abc1e9fe-b4ab-402c-ab21-11e97e3fde3a\Data\IsolatedStore";
                        WP7RootToolsSDK.FileSystem.CopyFile(@"\windows\mologo.bmp", dir + "\\mologo.bmp");
                    }
                    using (var stream = store.OpenFile("mologo.bmp", System.IO.FileMode.Open))
                    {
            #endif
            #if WP8
                        var iso = new ExtendedImage();
                        var dec = new ImageTools.IO.Bmp.BmpDecoder();
                        dec.Decode(iso, stream);
                        SplashImage.Source = iso.ToBitmap();
                        SplashImage.Visibility = Visibility.Visible;
                    }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Failed", MessageBoxButton.OK);
                    }
                });
                cmb.Show();
            #else
                        MessageBox.Show("Feature not implemented yet!");
                }
            #endif

            #if !WP8
            }