public static string CreateFile (string name, int size) { using (Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png")) { using (Gdk.Pixbuf tmp = test.ScaleSimple (size, size, Gdk.InterpType.Bilinear)) { string path = System.IO.Path.GetTempPath (); path = System.IO.Path.Combine (path, name); Console.WriteLine (path); string extension = System.IO.Path.GetExtension (path); string type = "null"; switch (extension.ToLower ()) { case ".jpg": case ".jpeg": type = "jpeg"; break; case ".png": type = "png"; break; case ".tiff": type = "tiff"; break; } tmp.Save (path, type); return path; } } }
private Gdk.Pixbuf GetIcon (int size) { if (Hit.GetFirstProperty ("beagle:Photo") != null) { Gdk.Pixbuf icon = new Gdk.Pixbuf (Hit.GetFirstProperty ("beagle:Photo")); return icon.ScaleSimple (size, size, Gdk.InterpType.Bilinear); } else return WidgetFu.LoadThemeIcon ("stock_person", size); }
private void CustomBuild() { this.PasswordEntry.Visibility = false; Gdk.Pixbuf pix = new Gdk.Pixbuf(null, "login_header.png"); pix = pix.ScaleSimple(this.Allocation.Width, this.TopImage.Allocation.Height, Gdk.InterpType.Bilinear); this.TopImage.Pixbuf = pix; this.Title = (string) SessionRegistry.GetInstance()["app_name"]; }
public string CreateFile(string name, int size) { using (Gdk.Pixbuf test = new Gdk.Pixbuf (null, "f-spot-32.png")) { using (Gdk.Pixbuf tmp = test.ScaleSimple (size, size, Gdk.InterpType.Nearest)) { string path = System.IO.Path.GetTempPath (); path = System.IO.Path.Combine (path, name); tmp.Save (path, Path.GetExtension (path).TrimStart (new char [] { '.' })); return path; } } }
public static Gdk.Pixbuf GetIcon(string iconName, int size) { try { return Gtk.IconTheme.Default.LoadIcon (iconName, size, 0); } catch (GLib.GException) {} try { Gdk.Pixbuf ret = new Gdk.Pixbuf (null, iconName + ".png"); return ret.ScaleSimple (size, size, Gdk.InterpType.Bilinear); } catch (ArgumentException) {} Logger.Debug ("Unable to load icon '{0}'.", iconName); return null; }
protected override void OnUpdatePreview() { try { if (String.IsNullOrEmpty (PreviewFilename)) { throw new ApplicationException (); } using (var pixbuf = new Gdk.Pixbuf (PreviewFilename)) { preview.Pixbuf = pixbuf.ScaleSimple (100, 100, Gdk.InterpType.Bilinear); } preview.Show (); } catch { preview.Hide (); } }
public RadioSourceContents() { HscrollbarPolicy = PolicyType.Never; VscrollbarPolicy = PolicyType.Automatic; viewport = new Viewport (); viewport.ShadowType = ShadowType.None; main_box = new VBox (); main_box.Spacing = 6; main_box.BorderWidth = 5; main_box.ReallocateRedraws = true; // Clamp the width, preventing horizontal scrolling SizeAllocated += delegate(object o, SizeAllocatedArgs args) { main_box.WidthRequest = args.Allocation.Width - 10; }; viewport.Add (main_box); StyleSet += delegate { viewport.ModifyBg (StateType.Normal, Style.Base (StateType.Normal)); viewport.ModifyFg (StateType.Normal, Style.Text (StateType.Normal)); }; logo_pix = new Gdk.Pixbuf (System.Reflection.Assembly.GetExecutingAssembly () .GetManifestResourceStream ("logo_color_large.gif")); logo = new Image (logo_pix); // auto-scale logo SizeAllocated += delegate(object o, SizeAllocatedArgs args) { int width = args.Allocation.Width - 50; logo.Pixbuf = logo_pix.ScaleSimple (width, (int)((float)width / 6.3f), Gdk.InterpType.Bilinear); }; main_box.PackStart (logo, false, false, 0); genres = new TitledList ("Genres"); main_box.PackStart (genres, false, false, 0); AddWithFrame (viewport); ShowAll (); }
private void UpdateIcons() { icon_names = job.IconNames; if (icon_pixbuf != null) { icon_pixbuf.Dispose (); icon_pixbuf = null; } if (icon_names == null || icon_names.Length == 0) { icon.Hide (); return; } icon_pixbuf = IconThemeUtils.LoadIcon (22, icon_names); if (icon_pixbuf != null) { icon.Pixbuf = icon_pixbuf; icon.Show (); return; } try { icon_pixbuf = new Gdk.Pixbuf (icon_names[0]); } catch (GLib.GException) {} if (icon_pixbuf != null) { Gdk.Pixbuf scaled = icon_pixbuf.ScaleSimple (22, 22, Gdk.InterpType.Bilinear); icon_pixbuf.Dispose (); icon.Pixbuf = scaled; icon.Show (); } }
protected override Gdk.Pixbuf OnGetPixbufForFile (string filename, Gtk.IconSize size) { NSImage icon = null; //FIXME: better handling of names of files that haven't been saved yet if (Path.IsPathRooted (filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile (filename); } else { icon = NSWorkspace.SharedWorkspace.IconForFile ("/tmp/" + filename); } if (icon != null) { int w, h; if (!Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h)) w = h = 22; var rect = new System.Drawing.RectangleF (0, 0, w, h); var rep = icon.BestRepresentation (rect, null, null) as NSBitmapImageRep; if (rep != null) { var tiff = rep.TiffRepresentation; byte[] arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, arr, 0, arr.Length); int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf (arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) return px; //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int) (w * ((float) ph / pw)); pw = w; } else { pw = (int) (h * ((float) pw / ph)); ph = h; } var scaled = px.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); px.Dispose (); return scaled; } } return base.OnGetPixbufForFile (filename, size); }
/// <summary> /// Charge une image de test. /// </summary> private static GreyPixbuf LoadImage(string ImagePath) { var pixbuf = new Gdk.Pixbuf(ImagePath); var scaledPixbuf = pixbuf.ScaleSimple(Config.WindowWidth, Config.WindowHeight, Gdk.InterpType.Hyper); pixbuf.Dispose(); return new GreyPixbuf(scaledPixbuf); }
public void SetIcon(Gdk.Pixbuf icon) { Properties.Set <Gdk.Pixbuf> ("Icon.Pixbuf_16", icon.ScaleSimple(16, 16, Gdk.InterpType.Bilinear)); }
protected override Gdk.Pixbuf OnGetPixbufForFile(string filename, Gtk.IconSize size) { NSImage icon = null; //FIXME: better handling of names of files that haven't been saved yet if (Path.IsPathRooted(filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile(filename); } else { icon = NSWorkspace.SharedWorkspace.IconForFile("/tmp/" + filename); } if (icon != null) { int w, h; if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } var rect = new System.Drawing.RectangleF(0, 0, w, h); var rep = icon.BestRepresentation(rect, null, null) as NSBitmapImageRep; if (rep != null) { var tiff = rep.TiffRepresentation; byte[] arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy(tiff.Bytes, arr, 0, arr.Length); int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf(arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) { return(px); } //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int)(w * ((float)ph / pw)); pw = w; } else { pw = (int)(h * ((float)pw / ph)); ph = h; } var scaled = px.ScaleSimple(pw, ph, Gdk.InterpType.Bilinear); px.Dispose(); return(scaled); } } return(base.OnGetPixbufForFile(filename, size)); }
private Widget CreateWidgets() { VBox vbox = new VBox(false, 0); AddAccountPixbuf = new Gdk.Pixbuf(Util.ImagesPath("add-account.png")); AddAccountPixbuf = AddAccountPixbuf.ScaleSimple(48, 48, Gdk.InterpType.Bilinear); AccountDruid = new Gnome.Druid(); vbox.PackStart(AccountDruid, true, true, 0); AccountDruid.ShowHelp = true; AccountDruid.Help += new EventHandler(OnAccountWizardHelp); AccountDruid.AppendPage(CreateIntroductoryPage()); AccountDruid.AppendPage(CreateServerInformationPage()); AccountDruid.AppendPage(CreateUserInformationPage()); AccountDruid.AppendPage(CreateConnectPage()); AccountDruid.AppendPage(CreateSummaryPage()); return vbox; }
private Widget CreateWidgets() { EventBox widgetEventbox = new EventBox(); widgetEventbox.ModifyBg(StateType.Normal, this.Style.Background(StateType.Normal)); VBox vbox = new VBox(false, 0); widgetEventbox.Add(vbox); KeyRecoveryPixbuf = new Gdk.Pixbuf(Util.ImagesPath("ifolder48.png")); KeyRecoveryPixbuf = KeyRecoveryPixbuf.ScaleSimple(48, 48, Gdk.InterpType.Bilinear); KeyRecoveryDruid = new Gnome.Druid(); vbox.PackStart(KeyRecoveryDruid, false,false ,0); KeyRecoveryDruid.ShowHelp = true; KeyRecoveryDruid.Help += new EventHandler(OnKeyRecoveryWizardHelp); KeyRecoveryDruid.AppendPage(CreateDomainSelectionPage()); KeyRecoveryDruid.AppendPage(CreateEnterPassphrasePage()); KeyRecoveryDruid.AppendPage(CreateInfoPage()); KeyRecoveryDruid.AppendPage(CreateSelectionPage()); KeyRecoveryDruid.AppendPage(CreateSingleWizPage()); KeyRecoveryDruid.AppendPage(CreateImportKeyPage()); KeyRecoveryDruid.AppendPage(CreateExportKeyPage()); KeyRecoveryDruid.AppendPage(CreateEmailPage()); KeyRecoveryDruid.AppendPage(CreateFinishPage()); return widgetEventbox; }
public override void Work() { ICommResult r = _in[0] as ICommResult; itest = new Gdk.Pixbuf[r.Length]; ibase = new Gdk.Pixbuf[r.OriginalBaseImages.Length]; double scale; for (int i = 0; i < itest.Length; i++) { IImage img = r.OriginalTestImages[i]; if (img.W > img.H) { scale = img.W / 32.0; } else { scale = img.H / 32.0; } Gdk.Pixbuf tmp = img.CreatePixbuf(); itest[i] = tmp.ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); } for (int i = 0; i < ibase.Length; i++) { IImage img = r.OriginalBaseImages[i]; if (img.W > img.H) { scale = img.W / 32.0; } else { scale = img.H / 32.0; } Gdk.Pixbuf tmp = img.CreatePixbuf(); ibase[i] = tmp.ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); } res = new IResult[r.Length]; for (int i = 0; i < r.Length; i++) { res[i] = r[i]; } match = r.FindResultsSimple(); for (int i = 0; i < r.Length; i++) { if (!r.Match[i]) { match[i] = -1; } } _workdone = true; }
public MainWindow() { Window win = new Window("Menu Sample App"); win.Resize(800, 650); VBox vbox = new VBox(false, 2); // menu bar MenuBar mb = new MenuBar(); Menu file_menu = new Menu(); MenuItem exit_item = new MenuItem("Exit"); MenuItem save_item = new MenuItem("Save"); MenuItem open_item = new MenuItem("Open"); exit_item.Activated += new EventHandler(on_exit_item_activate); file_menu.Append(open_item); file_menu.Append(save_item); file_menu.Append(exit_item); MenuItem file_item = new MenuItem("File"); file_item.Submenu = file_menu; mb.Append(file_item); vbox.PackStart(mb, false, false, 0); // toolbar Toolbar toolbar = new Toolbar(); ToolButton buttonMove = new ToggleToolButton(); buttonMove.IconWidget = new Gtk.Image("../ops/move.png"); ToolButton buttonSelect = new ToggleToolButton(); buttonSelect.IconWidget = new Gtk.Image("../ops/scale.png"); ToolButton buttonStar = new ToggleToolButton(); var pixbufStar = new Gdk.Pixbuf("../accessories/star.png"); buttonStar.IconWidget = new Gtk.Image(pixbufStar.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonAviator = new ToggleToolButton(); var pixbufAv = new Gdk.Pixbuf("../accessories/aviator.png"); buttonAviator.IconWidget = new Gtk.Image(pixbufAv.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonHeart = new ToggleToolButton(); var pixbufH = new Gdk.Pixbuf("../accessories/heart.png"); buttonHeart.IconWidget = new Gtk.Image(pixbufH.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonNerd = new ToggleToolButton(); var pixbufN = new Gdk.Pixbuf("../accessories/nerd.png"); buttonNerd.IconWidget = new Gtk.Image(pixbufN.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonHorns = new ToggleToolButton(); var pixbufHorns = new Gdk.Pixbuf("../accessories/horns.png"); buttonHorns.IconWidget = new Gtk.Image(pixbufHorns.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonHalo = new ToggleToolButton(); var pixbufHalo = new Gdk.Pixbuf("../accessories/halo.png"); buttonHalo.IconWidget = new Gtk.Image(pixbufHalo.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonTiara = new ToggleToolButton(); var pixbufT = new Gdk.Pixbuf("../accessories/tiara.png"); buttonTiara.IconWidget = new Gtk.Image(pixbufT.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonMous = new ToggleToolButton(); var pixbufM = new Gdk.Pixbuf("../accessories/moustache.png"); buttonMous.IconWidget = new Gtk.Image(pixbufM.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); ToolButton buttonLib = new ToggleToolButton(); var pixbufL = new Gdk.Pixbuf("../accessories/librarian.png"); buttonLib.IconWidget = new Gtk.Image(pixbufL.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); SeparatorToolItem sep = new SeparatorToolItem(); toolbar.Insert(buttonMove, -1); toolbar.Insert(buttonSelect, -1); toolbar.Insert(sep, -1); toolbar.Insert(buttonStar, -1); toolbar.Insert(buttonAviator, -1); toolbar.Insert(buttonHeart, -1); toolbar.Insert(buttonNerd, -1); toolbar.Insert(buttonHorns, -1); toolbar.Insert(buttonHalo, -1); toolbar.Insert(buttonTiara, -1); toolbar.Insert(buttonMous, -1); toolbar.Insert(buttonLib, -1); toolbar.ToolbarStyle = ToolbarStyle.BothHoriz; toolbar.ShowArrow = false; vbox.PackStart(toolbar, false, false, 0); ListView list = new ListView("Layer"); vbox.PackStart(list, false, false, 0); Gdk.Pixbuf backgroundImg = new Gdk.Pixbuf("../photos/kitty4.jpg"); Canvas canv = new Canvas(backgroundImg); vbox.PackStart(canv, false, false, 0); win.Add(vbox); win.ShowAll(); }
public void Refresh() { foreach (string i in SearchPath) {Console.WriteLine (i);} IconProvider provider = new IconProvider (""); string folder = provider.GetTargetFolderPath (); string [] files = Directory.GetFiles (folder); int [] sizes = {16, 24, 32, 48}; foreach (string file_path in files) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (file_path); FileInfo file_info = new FileInfo (file_path); // Delete the icon if it turns out to be empty if (file_info.Length == 0) { File.Delete (file_path); Console.WriteLine ("Deleted: " + file_path); } for (int i = 0; i < 4; i++) { int size = sizes [i]; Gdk.Pixbuf pixbuf_copy = pixbuf.Copy (); if (pixbuf.Width != size || pixbuf.Height != size) pixbuf_copy = pixbuf.ScaleSimple (size, size, Gdk.InterpType.Hyper); string size_folder_path = CombineMore (Path, size + "x" + size, "status"); string size_file_path = CombineMore (size_folder_path, System.IO.Path.GetFileName (file_path)); Directory.CreateDirectory (size_folder_path); if (File.Exists (size_file_path)) File.Delete (size_file_path); pixbuf_copy.Save (size_file_path, "png"); } File.Delete (file_path); } RescanIfNeeded (); }
private void ShowTrackNotification() { // This has to happen before the next if, otherwise the last_* members aren't set correctly. if (current_track == null || (notify_last_title == current_track.DisplayTrackTitle && notify_last_artist == current_track.DisplayArtistName)) { return; } notify_last_title = current_track.DisplayTrackTitle; notify_last_artist = current_track.DisplayArtistName; if (!show_notifications) { return; } foreach (var window in elements_service.ContentWindows) { if (window.HasToplevelFocus) { return; } } bool is_notification_daemon = false; try { var name = Notifications.Global.ServerInformation.Name; is_notification_daemon = name == "notification-daemon" || name == "Notification Daemon"; } catch { // This will be reached if no notification daemon is running return; } string message = GetByFrom( current_track.ArtistName, current_track.DisplayArtistName, current_track.AlbumTitle, current_track.DisplayAlbumTitle); if (artwork_manager_service == null) { artwork_manager_service = ServiceManager.Get <ArtworkManager> (); } Gdk.Pixbuf image = null; if (artwork_manager_service != null) { image = is_notification_daemon ? artwork_manager_service.LookupScalePixbuf(current_track.ArtworkId, 42) : artwork_manager_service.LookupPixbuf(current_track.ArtworkId); } if (image == null) { image = IconThemeUtils.LoadIcon(48, "audio-x-generic"); if (image != null) { image.ScaleSimple(42, 42, Gdk.InterpType.Bilinear); } } try { if (current_nf == null) { current_nf = new Notification(current_track.DisplayTrackTitle, message, image, notif_area.Widget); } else { current_nf.Summary = current_track.DisplayTrackTitle; current_nf.Body = message; current_nf.Icon = image; current_nf.AttachToWidget(notif_area.Widget); } current_nf.Urgency = Urgency.Low; current_nf.Timeout = 4500; if (!current_track.IsLive && ActionsSupported && interface_action_service.PlaybackActions["NextAction"].Sensitive) { current_nf.AddAction("skip-song", Catalog.GetString("Skip this item"), OnSongSkipped); } current_nf.Show(); } catch (Exception e) { Hyena.Log.Warning(Catalog.GetString("Cannot show notification"), e.Message, false); } }
private void HandleRenderingQueueProgressMessageReport(string source, string destination, double progress, string status, IBitmapCore image) { Application.Invoke(delegate { source_label.Text = source; destination_label.Text = destination; processing_progressbar.Fraction = progress; processing_progressbar.Text = status; mProcessingStatusIcon.Tooltip = "Processing " + System.IO.Path.GetFileName(source) + ". " + status + " (" + ((int)(progress * 100)).ToString() + "%)"; thumb_image.Visible = (image != null); if ((DateTime.Now - updateMoment).TotalMilliseconds > drawingTimeSpan.TotalMilliseconds * 5 && image != null && this.Visible) { updateMoment = DateTime.Now; // Drawing int size = 300, margins = 30; thumb_image.SetSizeRequest(size + margins, size + margins); using (Gdk.Pixmap pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1)) { using (Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height)) { using (Gdk.GC gc = new Gdk.GC(thumb_image.GdkWindow)) { ((FloatBitmapGtk)image).DrawToPixbuf(pb, null); Gdk.Pixbuf pb2; if (pb.Width > pb.Height) pb2 = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb2 = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); pm.DrawPixbuf(gc, pb2, 0, 0, (size + margins) / 2 - pb2.Width / 2, (size + margins) / 2 - pb2.Height / 2, pb2.Width, pb2.Height, Gdk.RgbDither.Max, 0, 0); pb2.Dispose(); thumb_image.SetFromPixmap(pm, null); } } } drawingTimeSpan = DateTime.Now - updateMoment; } }); }
// window is the scrolled window; should be named apropriately eventually public JsonClass(Gtk.Container window, Gtk.Image image, myListStore myListstore) { Gdk.Pixbuf tileSet = image.Pixbuf, scaled = image.Pixbuf; int height = tileSet.Height, width = tileSet.Width; // a treestore so the tiles with subtiles can be expanded, eventually also categories that are expandable Gtk.TreeStore myListStore = new Gtk.TreeStore(typeof(string), typeof(int), typeof(string), typeof(Gdk.Pixbuf)); tile_info_nested tile_info = new tile_info_nested(); // should have a better name eventually // should either be chosen by user or maybe the folder where the tileset resides StreamReader streamReader = new StreamReader(@"/home/gervinius/Pragramming/Mono/jsonTest/jsonTest/tile_config.json"); tile_info_nested deserializedJsonFile = JsonConvert.DeserializeObject <tile_info_nested> (streamReader.ReadToEnd()); streamReader.Close(); int value, tileWidthHeight = 16; if (deserializedJsonFile.tile_info [0].TryGetValue("height", out value)) { tileWidthHeight = value; Console.WriteLine(tileWidthHeight); } scaled = scaled.ScaleSimple(tileWidthHeight, tileWidthHeight, Gdk.InterpType.Bilinear); // temp solution; should look for a more elegant solution //this copies the list from the json object list to another list. Could be a better solution someday tile_info.tiles = new List <Json_tile_class> (deserializedJsonFile.tiles); //checks if tile has subtiles and adds them to a list for (int i = 0; i < tile_info.tiles.Count; i++) { if (tile_info.tiles [i].multitile == true) { //just copy the list with subtiles tile_info.tiles [i].additional_tiles = new List <Json_tile_class> (deserializedJsonFile.tiles[i].additional_tiles); } } //reads the tileset image and copies each individual tile to a pixbuf; should be a seperate method eventually for (int i = 0; i < height / tileWidthHeight; i++) { for (int h = 0; h < width / tileWidthHeight; h++) { tile_info.lstPixbuf.Add(scaled.Copy()); //hack to initialize a empty pixbuf at the correct index in the list, there may be a more performant solution tileSet.CopyArea(h * tileWidthHeight, i * tileWidthHeight, tileWidthHeight, tileWidthHeight, tile_info.lstPixbuf[i * 16 + h], 0, 0); //copy the pixels that reperesent one tile to the pixbuf at the lists index } } //checks whether the tile has a bg or fg image (or both) for (int i = 0; i < tile_info.tiles.Count; i++) { Gdk.Pixbuf myListstoreImage = scaled.Copy(); // initialize a pixbuf with 32x32 pixels;; could be in the class eventually if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0) // some persons have used the value -1 to mark a nonexisting fg- or bg-image { tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value]; myListstoreImage = tile_info.tiles [i].fg_image; } else if (tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0) { tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value]; myListstoreImage = tile_info.tiles [i].bg_image; } else if (tile_info.tiles [i].fg != null && tile_info.tiles [i].fg >= 0 && tile_info.tiles [i].bg != null && tile_info.tiles [i].bg >= 0) { tile_info.tiles[i].fg_image = tile_info.lstPixbuf[tile_info.tiles [i].fg.Value]; tile_info.tiles[i].bg_image = tile_info.lstPixbuf[tile_info.tiles [i].bg.Value]; // this merges background and foreground tile_info.tiles [i].bg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1); tile_info.tiles [i].fg_image.Composite(myListstoreImage, 0, 0, tileWidthHeight, tileWidthHeight, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 1); } // if the tile object has additional tiles ... if (tile_info.tiles [i].multitile == true) { // create an expandable treeiter Gtk.TreeIter iter = myListStore.AppendValues(tile_info.tiles[i].id); // category name is the maintiles name, could be changed later //append the PARENT TILE to the treestore myListStore.AppendValues(iter, tile_info.tiles [i].id, 1, "test1", myListstoreImage); // look through each subtile and add the foreground or background image to the liststore for (int x = 0; x < tile_info.tiles[i].additional_tiles.Count; x++) { if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0) { tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value]; myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].fg_image); } else if (tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0) { tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value]; myListStore.AppendValues(iter, tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].bg_image); // ToDo:: merge fg and bg } else if (tile_info.tiles [i].additional_tiles [x].fg != null && tile_info.tiles [i].additional_tiles [x].fg >= 0 && tile_info.tiles [i].additional_tiles [x].bg != null && tile_info.tiles [i].additional_tiles [x].bg >= 0) { tile_info.tiles [i].additional_tiles [x].fg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].fg.Value]; tile_info.tiles [i].additional_tiles [x].bg_image = tile_info.lstPixbuf [tile_info.tiles [i].additional_tiles [x].bg.Value]; myListStore.AppendValues(tile_info.tiles [i].additional_tiles [x].id, "test", "test1", tile_info.tiles [i].additional_tiles [x].fg_image); } } } else { // append the tile at index i to the liststore myListStore.AppendValues(tile_info.tiles [i].id, "test", "test1", myListstoreImage); } } myListstore.returnTV().Model = myListStore; }
public static Gdk.Pixbuf GetPixbufFromNSImageRep (NSImageRep rep, int width, int height) { var rect = new RectangleF (0, 0, width, height); var bitmap = rep as NSBitmapImageRep; if (bitmap == null) { using (var cgi = rep.AsCGImage (ref rect, null, null)) bitmap = new NSBitmapImageRep (cgi); } try { byte[] data; using (var tiff = bitmap.TiffRepresentation) { data = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, data, 0, data.Length); } int pw = bitmap.PixelsWide, ph = bitmap.PixelsHigh; var pixbuf = new Gdk.Pixbuf (data, pw, ph); // if one dimension matches, and the other is same or smaller, use as-is if ((pw == width && ph <= height) || (ph == height && pw <= width)) return pixbuf; // otherwise scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = width; ph = height; } else if (pw > ph) { ph = (int) (width * ((float) ph / pw)); pw = width; } else { pw = (int) (height * ((float) pw / ph)); ph = height; } var scaled = pixbuf.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); pixbuf.Dispose (); return scaled; } finally { if (bitmap != rep) bitmap.Dispose (); } }
protected void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; else idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; if (rdl.Description != "") idtext += "Description: <b>" + rdl.Description + "</b>\n"; Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. "+ "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) gc.Dispose(); if (pm != null) pm.Dispose(); } return false; })); } }
private Widget CreateWelcomePage() { VBox vbox = new VBox(false, 0); MenuBar menubar = CreateWelcomeMenuBar(); vbox.PackStart (menubar, false, false, 0); Frame frame = new Frame(); vbox.PackStart(frame, true, true, 0); vbox.ModifyBase(StateType.Normal, new Gdk.Color(255, 255, 255)); VBox welcomeVBox = new VBox(false, 0); frame.Add(welcomeVBox); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(Util.ImagesPath("ifolder128.png")); Image image = new Image(pixbuf); image.SetAlignment(0.5F, 0.5F); welcomeVBox.PackStart(image, false, false, 0); Label l = new Label( string.Format("<span size=\"x-large\" weight=\"bold\">{0}</span>", Util.GS("Welcome to iFolder"))); welcomeVBox.PackStart(l, false, false, 0); l.UseMarkup = true; l = new Label( string.Format("<span>{0}</span>", Util.GS("iFolder is a file sharing solution for workgroup and enterprise environments."))); welcomeVBox.PackStart(l, false, false, 0); l.UseMarkup = true; HBox hbox = new HBox(false, 0); ConnectToServerButton = new Button(hbox); ConnectToServerButton.Relief = ReliefStyle.None; vbox.PackStart(ConnectToServerButton, false, false, 0); Gdk.Pixbuf folderPixbuf = new Gdk.Pixbuf(Util.ImagesPath("add-account.png")); folderPixbuf = folderPixbuf.ScaleSimple(64, 64, Gdk.InterpType.Bilinear); Image folderImage = new Image(folderPixbuf); folderImage.SetAlignment(0.5F, 0F); hbox.PackStart(folderImage, false, false, 0); VBox buttonVBox = new VBox(false, 0); hbox.PackStart(buttonVBox, true, true, 4); Label buttonText = new Label(string.Format("<span size=\"large\" weight=\"bold\">{0}</span>", Util.GS("Connect to an iFolder Server"))); buttonVBox.PackStart(buttonText, false, false, 0); buttonText.UseMarkup = true; buttonText.UseUnderline = false; buttonText.Xalign = 0; Label buttonMessage = new Label(string.Format("<span size=\"small\">{0}</span>", Util.GS("Start synchronizing files by connecting to an iFolder server"))); buttonVBox.PackStart(buttonMessage, false, false, 0); buttonMessage.UseMarkup = true; buttonMessage.UseUnderline = false; buttonMessage.LineWrap = true; buttonMessage.Justify = Justification.Left; buttonMessage.Xalign = 0; buttonMessage.Yalign = 0; ConnectToServerButton.Clicked += new EventHandler(OnConnectToServerButton); return vbox; }
protected string CreateImageThumbnail(System.Drawing.Image Image, string Directory, int Width, int Height) { if(!System.IO.Directory.Exists(Directory)) System.IO.Directory.CreateDirectory(Directory); string shortname = Guid.NewGuid().ToString() + ".png"; string filename = System.IO.Path.Combine(Directory, shortname); using(System.IO.MemoryStream stream = new System.IO.MemoryStream()) { Image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Position = 0; using(Gdk.Pixbuf img = new Gdk.Pixbuf(stream)) { using(Gdk.Pixbuf pixbuf = img.ScaleSimple( Width, Height, Gdk.InterpType.Bilinear)) { pixbuf.Save(filename, "png"); // doc says "jpeg" is supported, but its not... return shortname; } } } }
private void SelectCurrent(object sender, EventArgs args) { this.ClearForm(); this.PhotoButton.Sensitive = true; this.PhotoButton.Relief = ReliefStyle.None; //default client info Client c = (Client) this.MembersNodeView.NodeSelection.SelectedNode; this.CurrentClient = c; Member m = new Member(); m.Id = c.Id; m.Sync(); c = m.InnerClient; //client info this.ActiveCheck.Active = m.Active; this.IdLabel.Text = c.Id.ToString("0000"); this.NameEntry.Text = c.Name; this.SurnameEntry.Text = c.Surname; this.AddressEntry.Text = c.Address; this.PhoneEntry.Text = c.PhoneNumber; this.EmailEntry.Text = c.Email; //member info this.WeightSpin.Value = m.Weight; this.HeightSpin.Value = m.Height; this.GenderCombo.Active = m.Gender == 'm' ? 0 : 1; this.BirthdayWidget.Date = m.BirthDate; this.ContactNameEntry.Text = !string.IsNullOrEmpty(m.InnerContact.Name) ? m.InnerContact.Name : ""; this.ContactPhoneEntry.Text = !string.IsNullOrEmpty(m.InnerContact.PhoneNumber) ? m.InnerContact.PhoneNumber : ""; if(m.BinImage != null && m.BinImage.Length > 0) { foreach(Widget widget in this.PhotoButton.Children) this.PhotoButton.Remove(widget); int h = this.PhotoButton.Allocation.Height; int w = this.PhotoButton.Allocation.Width; Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(m.BinImage); double x_scale = (double) w / pixbuf.Width; double y_scale = (double) h / pixbuf.Height; double scale = Math.Min(x_scale, y_scale); pixbuf = pixbuf.ScaleSimple((int) (pixbuf.Width * scale), (int) (pixbuf.Height * scale), Gdk.InterpType.Bilinear); this.PhotoButton.Add(new Gtk.Image(pixbuf)); this.PhotoButton.ShowAll(); } //payment info this.PaymentDaySpin.Value = m.PaymentDay; this.SinceWidget.Date = m.JoinDate; PackModel pm = new PackModel(); IDataReader reader = pm.GetById(m.Pack); if(reader.Read()) { string name = (string) reader["Name"]; long packs = pm.Count(); for(int i = 0; i < packs; i++) { this.PackCombo.Active = i; string text = this.PackCombo.ActiveText; if(name == text) break; } } //conf this.EditButton.Sensitive = true; }
public bool SetThumbnailIcon(Gtk.Image image, Beagle.Hit hit, int size) { DateTime mtime = (hit.FileInfo != null) ? hit.FileInfo.LastWriteTime : DateTime.Now; if (hit.MimeType == null || !factory.CanThumbnail(hit.EscapedUri, hit.MimeType, mtime)) { return(false); } string thumbnail = Gnome.Thumbnail.PathForUri(hit.EscapedUri, Gnome.ThumbnailSize.Normal); bool failed_thumb = factory.HasValidFailedThumbnail(hit.EscapedUri, mtime); if (!File.Exists(thumbnail) && !failed_thumb) { lock (in_queue) { in_queue.Add(new ThumbnailRequest(image, thumbnail, hit, size)); if (thread == null) { thread = new Thread(GenerateThumbnails); thread.Start(); } } return(false); } if (failed_thumb) { return(false); } Gdk.Pixbuf icon = new Gdk.Pixbuf(thumbnail); if (icon == null) { return(false); } int width = icon.Width, height = icon.Height; if (icon.Height > size) { if (icon.Width > icon.Height) { width = size; height = (size * icon.Height) / icon.Width; } else { height = size; width = (size * icon.Width) / icon.Height; } } else if (icon.Width > size) { width = size; height = (size * icon.Height) / icon.Width; } icon = icon.ScaleSimple(width, height, Gdk.InterpType.Bilinear); image.Pixbuf = icon; return(true); }
protected override Gdk.Pixbuf OnGetPixbufForFile (string filename, Gtk.IconSize size) { //this only works on MacOS 10.6.0 and greater if (systemVersion < 0x1060) return base.OnGetPixbufForFile (filename, size); NSImage icon = null; if (Path.IsPathRooted (filename) && File.Exists (filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile (filename); } else { string extension = Path.GetExtension (filename); if (!string.IsNullOrEmpty (extension)) icon = NSWorkspace.SharedWorkspace.IconForFileType (extension); } if (icon == null) { return base.OnGetPixbufForFile (filename, size); } int w, h; if (!Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } var rect = new System.Drawing.RectangleF (0, 0, w, h); var arep = icon.BestRepresentation (rect, null, null); if (arep == null) { return base.OnGetPixbufForFile (filename, size); } var rep = arep as NSBitmapImageRep; if (rep == null) { using (var cgi = arep.AsCGImage (rect, null, null)) rep = new NSBitmapImageRep (cgi); arep.Dispose (); } try { byte[] arr; using (var tiff = rep.TiffRepresentation) { arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy (tiff.Bytes, arr, 0, arr.Length); } int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf (arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) return px; //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int) (w * ((float) ph / pw)); pw = w; } else { pw = (int) (h * ((float) pw / ph)); ph = h; } var scaled = px.ScaleSimple (pw, ph, Gdk.InterpType.Bilinear); px.Dispose (); return scaled; } finally { if (rep != null) rep.Dispose (); } }
private Widget CreateWidgets() { EventBox widgetEventbox = new EventBox(); widgetEventbox.ModifyBg(StateType.Normal, this.Style.Background(StateType.Normal)); VBox vbox = new VBox(false, 0); widgetEventbox.Add(vbox); AddAccountPixbuf = new Gdk.Pixbuf(Util.ImagesPath("ifolder-add-account48.png")); AddAccountPixbuf = AddAccountPixbuf.ScaleSimple(48, 48, Gdk.InterpType.Bilinear); AccountDruid = new Gnome.Druid(); vbox.PackStart(AccountDruid, true, true, 0); AccountDruid.ShowHelp = true; AccountDruid.Help += new EventHandler(OnAccountWizardHelp); AccountDruid.AppendPage(CreateIntroductoryPage()); AccountDruid.AppendPage(CreateServerInformationPage()); AccountDruid.AppendPage(CreateUserInformationPage()); AccountDruid.AppendPage(CreateConnectPage()); AccountDruid.AppendPage(CreateRAPage()); AccountDruid.AppendPage(CreateDefaultiFolderPage()); AccountDruid.AppendPage(CreateSummaryPage()); AccountDruid.SetButtonsSensitive(false, true, true, true); return widgetEventbox; }
private void LoadPreviewIcon() { string vmss = CheckPointFileName; if (vmss == null || !File.Exists (vmss)) return; int header = BitConverter.ToInt32 (new byte[] { 0x89, (byte) 'P', (byte) 'N', (byte) 'G' }, 0); int chunkSize = 1024; using (FileStream stream = File.OpenRead (vmss)) { byte[] chunk = new byte[chunkSize]; for (;;) { int len = stream.Read (chunk, 0, chunkSize); if (len == 0) break; for (int i = 0; i < len - 4; i++) { int val = BitConverter.ToInt32 (chunk, i); if (val == header) { stream.Seek (-(len - i), SeekOrigin.Current); try { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (stream); double scale = Math.Min (PreviewIconSize / (double) pixbuf.Width, PreviewIconSize / (double) pixbuf.Height); int scaleWidth = (int) (scale * pixbuf.Width); int scaleHeight = (int) (scale * pixbuf.Height); icon = pixbuf.ScaleSimple (scaleWidth, scaleHeight, Gdk.InterpType.Bilinear); } catch { } return; } } } } }
public override void Work() { ICommResult r = _in[0] as ICommResult; int[] res = r.FindResultsSimple(); int numcat = FindNumCategories(r.TestCategories); cat = new Category[numcat + 1]; for (int i = 0; i < numcat + 1; i++) { cat[i] = new Category(); } total = r.Length; matched = 0; for (int i = 0; i < r.Length; i++) { int tc = r.TestCategory(i); int bc = r.BaseCategory(res[i]); cat[tc].total++; if (cat[tc].image == null) { double scale; IImage img = null; for (int j = 0; j < r.OriginalBaseImages.Length; j++) { if (r.BaseCategory(j) == tc) { img = r.OriginalBaseImages[j]; if (first) { break; } } } if (img == null) { cat[tc].image = new Gdk.Pixbuf(Assembly.GetEntryAssembly(), "no-base.png"); } else { if (img.W > img.H) { scale = img.W / 48.0; } else { scale = img.H / 48.0; } Gdk.Pixbuf tmp = img.CreatePixbuf(); cat[tc].image = tmp.ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); } } if (tc == bc && r.Match[i]) { cat[tc].matched++; matched++; } } _workdone = true; }
public static Gdk.Pixbuf GetMiniIcon (string resource_name) { Gdk.Pixbuf noicon = new Gdk.Pixbuf (null, resource_name); return noicon.ScaleSimple (24, 24, Gdk.InterpType.Nearest); }
private void on_avatarButton_clicked(object o, EventArgs args) { FileSelector selector = new FileSelector ("Select Image"); selector.Show (); int result = selector.Run (); if (result == (int)Gtk.ResponseType.Ok) { try { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (selector.Filename); if (pixbuf.Width > 80 | pixbuf.Height > 80) pixbuf = pixbuf.ScaleSimple (80, 80, Gdk.InterpType.Hyper); avatarImage.Pixbuf = pixbuf; avatarImage.Sensitive = true; } catch (Exception ex) { selector.Hide (); Gui.ShowMessageDialog (ex.Message); return; } } selector.Hide (); }
public void Update() { Dispose(); if(spectator.Image == null) { image = ResourceManager.GetPixbuf("Resources", "DefaultPlayerImage.png"); if(image != null) image = image.ScaleSimple(16, 16, Gdk.InterpType.Bilinear); } else image = PictureManager.GetPixbuf(spectator.Image, 16); OnChanged(); }
private void on_avatarButton_drag_data_received(object sender, DragDataReceivedArgs args) { if (args.SelectionData.Length >=0 && args.SelectionData.Format == 8) { //Console.WriteLine ("Received {0} in label", args.SelectionData.Text); try { string fileName = new Uri (args.SelectionData.Text.Trim ()).LocalPath; Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (fileName); if (pixbuf.Width > 80 | pixbuf.Height > 80) pixbuf = pixbuf.ScaleSimple (80, 80, Gdk.InterpType.Hyper); avatarImage.Pixbuf = pixbuf; avatarImage.Sensitive = true; } catch (Exception ex) { Gui.ShowMessageDialog (ex.Message); } } Gtk.Drag.Finish (args.Context, false, false, args.Time); }
private void DrawImageSized(PageImage pi, Gdk.Pixbuf im, Cairo.Context g, Cairo.Rectangle r) { double height, width; // some work variables StyleInfo si = pi.SI; // adjust drawing rectangle based on padding // System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft), // r.Top + PixelsY(si.PaddingTop), // r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), // r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle r2 = new Cairo.Rectangle(r.X + PixelsX(si.PaddingLeft), r.Y + PixelsY(si.PaddingTop), r.Width - PixelsX(si.PaddingLeft + si.PaddingRight), r.Height - PixelsY(si.PaddingTop + si.PaddingBottom)); Cairo.Rectangle ir; // int work rectangle switch (pi.Sizing) { case ImageSizingEnum.AutoSize: // // Note: GDI+ will stretch an image when you only provide // // the left/top coordinates. This seems pretty stupid since // // it results in the image being out of focus even though // // you don't want the image resized. // if (g.DpiX == im.HorizontalResolution && // g.DpiY == im.VerticalResolution) float imwidth = PixelsX(im.Width); float imheight = PixelsX(im.Height); ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), imwidth, imheight); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); //g.DrawImage(im, ir); im = im.ScaleSimple((int)r2.Width, (int)r2.Height, Gdk.InterpType.Hyper); g.DrawPixbufRect(im, ir); break; case ImageSizingEnum.Clip: // Region saveRegion = g.Clip; g.Save(); // Region clipRegion = new Region(g.Clip.GetRegionData()); // clipRegion.Intersect(r2); // g.Clip = clipRegion; g.Rectangle(r2); g.Clip(); // if (dpiX == im.HorizontalResolution && // dpiY == im.VerticalResolution) ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), im.Width, im.Height); // else // ir = new Cairo.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y), // Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height)); // g.DrawImage(im, ir); g.DrawPixbufRect(im, ir); // g.Clip = saveRegion; g.Restore(); break; case ImageSizingEnum.FitProportional: double ratioIm = (float)im.Height / (float)im.Width; double ratioR = r2.Height / r2.Width; height = r2.Height; width = r2.Width; if (ratioIm > ratioR) { // this means the rectangle width must be corrected width = height * (1 / ratioIm); } else if (ratioIm < ratioR) { // this means the ractangle height must be corrected height = width * ratioIm; } r2 = new Cairo.Rectangle(r2.X, r2.Y, width, height); g.DrawPixbufRect(im, r2); break; case ImageSizingEnum.Fit: default: g.DrawPixbufRect(im, r2); break; } }
public MainWindow() : base("Main Window") { SetDefaultSize(800, 650); DeleteEvent += new DeleteEventHandler(delete_cb); bool isUniform = false; int margin = 5; VBox topPanel = new VBox(isUniform, margin); HBox layCan = new HBox(isUniform, margin); VBox layout = new VBox(isUniform, margin); VBox layBtn = new VBox(isUniform, margin); ButtonPressEvent += new ButtonPressEventHandler(ButtonPressHandler); MotionNotifyEvent += new MotionNotifyEventHandler(MotionNotifyHandler); ButtonReleaseEvent += new ButtonReleaseEventHandler(ButtonReleaseHandler); // menu bar MenuBar mb = new MenuBar(); Menu file_menu = new Menu(); MenuItem exit_item = new MenuItem("Exit"); MenuItem save_item = new MenuItem("Save"); MenuItem open_item = new MenuItem("Open"); exit_item.Activated += new EventHandler(on_exit_item_activate); open_item.Activated += new EventHandler(OnOpenCallback); save_item.Activated += new EventHandler(onSaveCallback); file_menu.Append(open_item); file_menu.Append(save_item); file_menu.Append(exit_item); MenuItem file_item = new MenuItem("File"); file_item.Submenu = file_menu; mb.Append(file_item); layout.Add(Align(mb, 0, 0.5f, 1, 1)); // toolbar Toolbar toolbar = new Toolbar(); ToolButton buttonMove = new ToggleToolButton(); buttonMove.IconWidget = new Gtk.Image("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/ops/move.png"); buttonMove.Clicked += new EventHandler(OnMoveClick); ToolButton buttonSelect = new ToggleToolButton(); buttonSelect.IconWidget = new Gtk.Image("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/ops/scale.png"); buttonSelect.Clicked += new EventHandler(OnSelectClick); ToolButton buttonStar = new ToggleToolButton(); var pixbufStar = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/star.png"); buttonStar.IconWidget = new Gtk.Image(pixbufStar.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonStar.Clicked += new EventHandler(OnStarClick); ToolButton buttonAviator = new ToggleToolButton(); var pixbufAv = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/aviator.png"); buttonAviator.IconWidget = new Gtk.Image(pixbufAv.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonAviator.Clicked += new EventHandler(OnAviatorClick); ToolButton buttonHeart = new ToggleToolButton(); var pixbufH = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/heart.png"); buttonHeart.IconWidget = new Gtk.Image(pixbufH.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonHeart.Clicked += new EventHandler(OnHeartClick); ToolButton buttonNerd = new ToggleToolButton(); var pixbufN = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/nerd.png"); buttonNerd.IconWidget = new Gtk.Image(pixbufN.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonNerd.Clicked += new EventHandler(OnNerdClick); ToolButton buttonHorns = new ToggleToolButton(); var pixbufHorns = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/horns.png"); buttonHorns.IconWidget = new Gtk.Image(pixbufHorns.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonHorns.Clicked += new EventHandler(OnHornsClick); ToolButton buttonHalo = new ToggleToolButton(); var pixbufHalo = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/halo.png"); buttonHalo.IconWidget = new Gtk.Image(pixbufHalo.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonHalo.Clicked += new EventHandler(OnHaloClick); ToolButton buttonTiara = new ToggleToolButton(); var pixbufT = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/tiara.png"); buttonTiara.IconWidget = new Gtk.Image(pixbufT.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonTiara.Clicked += new EventHandler(OnTiaraClick); ToolButton buttonMous = new ToggleToolButton(); var pixbufM = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/moustache.png"); buttonMous.IconWidget = new Gtk.Image(pixbufM.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonMous.Clicked += new EventHandler(OnMousClick); ToolButton buttonLib = new ToggleToolButton(); var pixbufL = new Gdk.Pixbuf("/Users/eliaanagnostou/Documents/cs71/03-photobooth-eanagno1-zbatool1/accessories/librarian.png"); buttonLib.IconWidget = new Gtk.Image(pixbufL.ScaleSimple(30, 30, Gdk.InterpType.Bilinear)); buttonLib.Clicked += new EventHandler(OnLibClick); SeparatorToolItem sep = new SeparatorToolItem(); toolbar.Insert(buttonMove, -1); toolbar.Insert(buttonSelect, -1); toolbar.Insert(sep, -1); toolbar.Insert(buttonStar, -1); toolbar.Insert(buttonAviator, -1); toolbar.Insert(buttonHeart, -1); toolbar.Insert(buttonNerd, -1); toolbar.Insert(buttonHorns, -1); toolbar.Insert(buttonHalo, -1); toolbar.Insert(buttonTiara, -1); toolbar.Insert(buttonMous, -1); toolbar.Insert(buttonLib, -1); toolbar.ToolbarStyle = ToolbarStyle.BothHoriz; toolbar.ShowArrow = false; layout.Add(Align(toolbar, 0, 0.25f, 1, 0)); layBtn.Add(Align(_list, 1, 0, 0, 1)); Button btn = new Button("Delete layer"); btn.Clicked += new EventHandler(btn_click); layBtn.Add(Align(btn, 0, 0, 1, 1)); layCan.Add(Align(layBtn, 1, 0, 0, 1)); layCan.Add(Align(_canv, 1, 0, 1, 1)); topPanel.Add(Align(layout, 1, 0, 1, 1)); topPanel.Add(Align(layCan, 1, 0, 0, 1)); Add(topPanel); ShowAll(); }
protected override Gdk.Pixbuf OnGetPixbufForFile(string filename, Gtk.IconSize size) { //this only works on MacOS 10.6.0 and greater if (systemVersion < 0x1060) { return(base.OnGetPixbufForFile(filename, size)); } NSImage icon = null; if (Path.IsPathRooted(filename) && File.Exists(filename)) { icon = NSWorkspace.SharedWorkspace.IconForFile(filename); } else { string extension = Path.GetExtension(filename); if (!string.IsNullOrEmpty(extension)) { icon = NSWorkspace.SharedWorkspace.IconForFileType(extension); } } if (icon == null) { return(base.OnGetPixbufForFile(filename, size)); } int w, h; if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out w, out h)) { w = h = 22; } var rect = new System.Drawing.RectangleF(0, 0, w, h); var arep = icon.BestRepresentation(rect, null, null); if (arep == null) { return(base.OnGetPixbufForFile(filename, size)); } var rep = arep as NSBitmapImageRep; if (rep == null) { using (var cgi = arep.AsCGImage(rect, null, null)) rep = new NSBitmapImageRep(cgi); arep.Dispose(); } try { byte[] arr; using (var tiff = rep.TiffRepresentation) { arr = new byte[tiff.Length]; System.Runtime.InteropServices.Marshal.Copy(tiff.Bytes, arr, 0, arr.Length); } int pw = rep.PixelsWide, ph = rep.PixelsHigh; var px = new Gdk.Pixbuf(arr, pw, ph); //if one dimension matches, and the other is same or smaller, use as-is if ((pw == w && ph <= h) || (ph == h && pw <= w)) { return(px); } //else scale proportionally such that the largest dimension matches the desired size if (pw == ph) { pw = w; ph = h; } else if (pw > ph) { ph = (int)(w * ((float)ph / pw)); pw = w; } else { pw = (int)(h * ((float)pw / ph)); ph = h; } var scaled = px.ScaleSimple(pw, ph, Gdk.InterpType.Bilinear); px.Dispose(); return(scaled); } finally { if (rep != null) { rep.Dispose(); } } }
private void UpdateImage(bool forceUpdate) { if (this.image == null || this.image.Anim == null) { return; } Gdk.PixbufAnimation animation; animation = this.image.Anim; // if (this.areaSize.X <= 2 || this.areaSize.Y <= 2) { return; } Gdk.Pixbuf unscaledPixBuf = null; bool newAnimFrame = false; if (animation.IsStaticImage) { if (forceUpdate) { unscaledPixBuf = animation.StaticImage; } } else { if (this.animIter == null) { animIter = animation.GetIter(IntPtr.Zero); } if (animIter != null && animIter.Advance(IntPtr.Zero)) { unscaledPixBuf = animIter.Pixbuf; newAnimFrame = true; } } var imageSize = new Cairo.PointD(animation.Width, animation.Height); if (imageSize.X <= 2 || imageSize.Y <= 2) { return; } // scale preserving aspect ratio var scale = Math.Min(this.areaSize.X / imageSize.X, this.areaSize.Y / imageSize.Y); var scaledImageSize = new Cairo.PointD(imageSize.X * scale, imageSize.Y * scale); if (unscaledPixBuf == null) { return; } if (newAnimFrame || unscaledPixBuf != this.unscaledPixBuf || scaledImageSize.X != this.scaledImageSize.X || scaledImageSize.Y != this.scaledImageSize.Y) { if (this.ScaledPixbuf != null) { this.ScaledPixbuf.Dispose(); } Gdk.Pixbuf scaledPixBuf = unscaledPixBuf.ScaleSimple((int)scaledImageSize.X, (int)scaledImageSize.Y, Gdk.InterpType.Hyper); this.ScaledPixbuf = scaledPixBuf; this.scaledImageSize = scaledImageSize; this.unscaledPixBuf = unscaledPixBuf; } // where to draw the pixbuf this.TargetRect = new Cairo.Rectangle( (this.areaSize.X - this.scaledImageSize.X) / 2, (this.areaSize.Y - this.scaledImageSize.Y) / 2, this.scaledImageSize.X, this.scaledImageSize.Y ); this.QueueFrame(); }
SImage Scale(SImage pix, int maxWidth, int maxHeight) { int width, height; ComputeScale(pix.Width, pix.Height, maxWidth, maxHeight, out width, out height); return pix.ScaleSimple(width, height, Gdk.InterpType.Bilinear); }
public static void DrawPixbufRect(this Context g, Gdk.Pixbuf pixbuf, Rectangle r) { Gdk.Pixbuf scaled = pixbuf.ScaleSimple((int)r.Width, (int)r.Height, Gdk.InterpType.Bilinear); g.DrawPixbuf(scaled, (int)r.X, (int)r.Y); }
/// <summary> /// Loads an image from a supplied bitmap. /// </summary> /// <param name="bitmap">The image to display.</param> public void LoadImage(Bitmap bitmap) { imagePixbuf = ImageToPixbuf(bitmap); // We should do a better job of rescaling the image. Any ideas? double scaleFactor = Math.Min(250.0 / imagePixbuf.Height, 250.0 / imagePixbuf.Width); image1.Pixbuf = imagePixbuf.ScaleSimple((int)(imagePixbuf.Width * scaleFactor), (int)(imagePixbuf.Height * scaleFactor), Gdk.InterpType.Bilinear); image1.Visible = true; scrolledwindow1.HscrollbarPolicy = PolicyType.Never; }
public override void Work() { ICommResult r = _in[0] as ICommResult; itest = new Gdk.Pixbuf[r.Length]; thumbs = new Gdk.Pixbuf[r.Length]; ibase = new Gdk.Pixbuf[r.OriginalBaseImages.Length]; double scale; for (int i = 0; i < itest.Length; i++) { IImage _img = r.OriginalTestImages[i]; IImage img = new IImage(_img.BPP, _img.W, _img.H, _img.Data, invert); if (invert) { img.Invert(); } if (img.W > img.H) { scale = img.W / 256.0; } else { scale = img.H / 256.0; } Gdk.Pixbuf tmp = img.CreatePixbuf(); itest[i] = tmp.ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); if (img.W > img.H) { scale = img.W / 64.0; } else { scale = img.H / 64.0; } thumbs[i] = itest[i].ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); } for (int i = 0; i < ibase.Length; i++) { IImage _img = r.OriginalBaseImages[i]; IImage img = new IImage(_img.BPP, _img.W, _img.H, _img.Data, invert); if (invert) { img.Invert(); } if (img.W > img.H) { scale = img.W / 256.0; } else { scale = img.H / 256.0; } Gdk.Pixbuf tmp = img.CreatePixbuf(); ibase[i] = tmp.ScaleSimple(Scale(img.W, scale), Scale(img.H, scale), Gdk.InterpType.Bilinear); } res = r.FindResultsSimple(); cat1 = r.BaseCategories; cat2 = r.TestCategories; match = r.Match; _workdone = true; }
private MenuBar CreateWelcomeMenuBar() { MenuBar menubar = new MenuBar (); AccelGroup agrp = new AccelGroup(); this.AddAccelGroup(agrp); Menu menu = new Menu(); ImageMenuItem imageMenuItem = new ImageMenuItem (Util.GS("Connect to a _server")); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(Util.ImagesPath("add-account.png")); pixbuf = pixbuf.ScaleSimple(24, 24, Gdk.InterpType.Bilinear); imageMenuItem.Image = new Image(pixbuf); menu.Append(imageMenuItem); imageMenuItem.AddAccelerator("activate", agrp, new AccelKey(Gdk.Key.S, Gdk.ModifierType.ControlMask, AccelFlags.Visible)); imageMenuItem.Activated += new EventHandler(OnAddNewAccount); menu.Append(new SeparatorMenuItem()); imageMenuItem = new ImageMenuItem (Stock.Close, agrp); menu.Append(imageMenuItem); imageMenuItem.Activated += new EventHandler(CloseEventHandler); imageMenuItem = new ImageMenuItem(Stock.Quit, agrp); menu.Append(imageMenuItem); imageMenuItem.Activated += new EventHandler(QuitEventHandler); MenuItem menuItem = new MenuItem(Util.GS("i_Folder")); menuItem.Submenu = menu; menubar.Append (menuItem); menu = new Menu(); imageMenuItem = new ImageMenuItem(Util.GS("_Preferences")); imageMenuItem.Image = new Image(Stock.Preferences, Gtk.IconSize.Menu); menu.Append(imageMenuItem); imageMenuItem.Activated += new EventHandler(ShowPreferencesHandler); menuItem = new MenuItem(Util.GS("_Edit")); menuItem.Submenu = menu; menubar.Append(menuItem); menu = new Menu(); imageMenuItem = new ImageMenuItem(Stock.Help, agrp); menu.Append(imageMenuItem); imageMenuItem.Activated += new EventHandler(OnHelpMenuItem); imageMenuItem = new ImageMenuItem(Util.GS("A_bout")); imageMenuItem.Image = new Image(Gnome.Stock.About, Gtk.IconSize.Menu); menu.Append(imageMenuItem); imageMenuItem.Activated += new EventHandler(OnAbout); menuItem = new MenuItem(Util.GS("_Help")); menuItem.Submenu = menu; menubar.Append(menuItem); return menubar; }
private void make() { buttons = new Button[buttonCount]; Grid buttonGrid = new Grid(); heartGrid.ColumnHomogeneous = true; buttonGrid.ColumnHomogeneous = true; // buttonGrid.RowHomogeneous = true; scoreProgressBar.Orientation = Orientation.Vertical; scoreProgressBar.Inverted = true; timer.StyleContext.AddClass("progressbar"); scoreProgressBar.StyleContext.AddClass("progressbar"); questionLabel.StyleContext.AddClass("BigLabel"); timer.ShowText = true; scoreProgressBar.Halign = Align.Center; scoreProgressBar.MarginEnd = 30; for (int i = 0; i < buttons.Length; i++) { buttons[i] = new Button(); buttons[i].StyleContext.AddClass("answerButton"); int devide = 60 / buttonCount; buttonGrid.Attach(buttons[i], i * devide + 1, 1, devide, 1); } int height = 0; int width = 0; GetSize(out width, out height); int imageheight = height / 5; for (int i = 0; i < 5; i++) { Gdk.Pixbuf pixbuf = new Gdk.Pixbuf("heart-solid.png"); pixbuf = pixbuf.ScaleSimple(imageheight, imageheight, Gdk.InterpType.Bilinear); images[i] = new Image(pixbuf); heartGrid.Attach(images[i], i + 1, 1, 1, 1); } // buttonGrid.MarginBottom = 125; buttonGrid.RowHomogeneous = true; timer.Valign = Align.Start; levelLabel.Halign = Align.Start; rankGrid.Attach(nextScoreLabel, 1, 1, 1, 1); if (offline) { rankGrid.Attach(presScoreLabel, 1, 2, 2, 4); } else { rankGrid.Attach(scoreProgressBar, 1, 2, 1, 2); rankGrid.Attach(presScoreLabel, 2, 2, 1, 2); } rankGrid.Attach(prevScroeLabel, 1, 4, 1, 1); scoreProgressBar.Halign = Align.Center; rankGrid.RowHomogeneous = true; rankGrid.ColumnHomogeneous = true; nextScoreLabel.Valign = Align.End; prevScroeLabel.Valign = Align.Start; main.Attach(levelLabel, 1, 1, 1, 1); levelLabel.MarginBottom = 20; main.Attach(rankGrid, 1, 2, 1, 3); main.Attach(questionLabel, 2, 1, 3, 2); main.Attach(buttonGrid, 2, 3, 3, 1); main.Attach(heartGrid, 2, 4, 3, 1); main.Attach(timer, 5, 1, 1, 1); ShowAll(); new Thread(new ThreadStart(countdown)).Start(); new Thread(new ThreadStart(game)).Start(); }
/// <summary> /// Loads an image from a manifest resource. /// </summary> public void LoadImage() { System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file = thisExe.GetManifestResourceStream("ApsimNG.Resources.PresenterPictures." + ModelName + ".png"); if (file == null) image1.Visible = false; else { imagePixbuf = new Gdk.Pixbuf(null, "ApsimNG.Resources.PresenterPictures." + ModelName + ".png"); // We should do a better job of rescaling the image. Any ideas? double scaleFactor = Math.Min(250.0 / imagePixbuf.Height, 250.0 / imagePixbuf.Width); image1.Pixbuf = imagePixbuf.ScaleSimple((int)(imagePixbuf.Width * scaleFactor), (int)(imagePixbuf.Height * scaleFactor), Gdk.InterpType.Bilinear); image1.Visible = true; scrolledwindow1.HscrollbarPolicy = PolicyType.Never; } }
public static Gdk.Pixbuf GetMiniIcon(string resource_name) { Gdk.Pixbuf noicon = new Gdk.Pixbuf(null, resource_name); return(noicon.ScaleSimple(24, 24, Gdk.InterpType.Nearest)); }