BioImager  5.0.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
OMERO.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Drawing.Imaging;
7using System.Linq;
8using System.Text;
9using System.Threading.Tasks;
10using System.Windows.Forms;
11using System.Drawing;
12using BioLib;
13using Gdk;
14using Graphics = System.Drawing.Graphics;
15using Bitmap = System.Drawing.Bitmap;
16using OMERO = BioLib.OMERO;
17using Rectangle = System.Drawing.Rectangle;
18namespace BioImager
19{
20 public partial class OMERO : Form
21 {
22 public List<omero.gateway.model.DatasetData> datas = new List<omero.gateway.model.DatasetData>();
23 private List<ListViewItem> items = new List<ListViewItem>();
24 public int selectedIndex = 0;
25 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
26 public int Progress
27 {
28 get { return progressBar.Value; }
29 set
30 {
31 if(value < 100)
32 progressBar.Value = value;
33
34 }
35 }
36 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
37 public string Status
38 {
39 get { return statusLabel.Text; }
40 set { statusLabel.Text = value; }
41 }
42 public OMERO()
43 {
44 InitializeComponent();
45 Login log = new Login();
46 if (log.ShowDialog() == DialogResult.OK)
47 {
48 BioLib.OMERO.Connect(Login.host, Login.port, Login.username, Login.password);
49 Init();
50 }
51 }
52 private void Init()
53 {
54 BioLib.OMERO.ReConnect();
55 var dst = BioLib.OMERO.GetDatasetsData();
56 datas.AddRange(dst);
57 foreach (var src in dst)
58 {
59 if (src != null)
60 {
61 comboBox1.Items.Add(src.getName() + " " + src.getId());
62 }
63 }
64 }
65 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
66 {
67 listView1.Items.Clear();
68 items.Clear();
69 string[] sts = comboBox1.SelectedItem.ToString().Split(" ");
70 List<ListViewItem> lss = new List<ListViewItem>();
71 foreach (omero.gateway.model.DatasetData s in datas)
72 {
73 if (s.getId().ToString() == sts[1].ToString())
74 {
75 Status = "Getting dataset information.";
76 List<string> fs = new List<string>();
77 List<long> ids = BioLib.OMERO.GetDatasetIds(s.getId());
78 foreach (long id in ids)
79 {
80 fs.Add(BioLib.OMERO.GetNameFromID(id));
81 }
82 if (loadIconsBox.Checked)
83 {
84 Status = "Loading icons...";
85 // Create ImageList
86 ImageList ims = new ImageList
87 {
88 ImageSize = new System.Drawing.Size(64, 64), // Set icon size (width x height)
89 ColorDepth = ColorDepth.Depth32Bit // Set color depth
90 };
91 Dictionary<long, Pixbuf> dict = BioLib.OMERO.GetThumbnails(fs.ToArray(), 64, 64);
92 int i = 0;
93 Status = "Loading files...";
94 foreach (var item in ids)
95 {
96 foreach (var itm in dict)
97 {
98 if(item == itm.Key)
99 {
100 Bitmap bm = PixbufToBitmap(itm.Value);
101 ims.Images.Add(bm);
102 ListViewItem li = new ListViewItem();
103 li.Text = fs[i];
104 li.ImageIndex = i;
105 items.Add(li);
106 Progress = (int)(((float)(i + 1) / (float)(ids.Count)) * 100);
107 i++;
108 }
109 }
110 }
111 listView1.SmallImageList = ims;
112 listView1.LargeImageList = ims;
113 listView1.View = View.LargeIcon;
114 listView1.Items.AddRange(items.ToArray());
115 Status = "";
116 Progress = 0;
117 return;
118 }
119 else
120 {
121 Status = "Loading files...";
122 int i = 0;
123 foreach (var item in ids)
124 {
125 ListViewItem li = new ListViewItem();
126 li.Text = fs[i];
127 items.Add(li);
128 Progress = (int)(((float)(i + 1) / (float)(ids.Count)) * 100);
129 i++;
130 }
131 listView1.View = View.List;
132 listView1.Items.AddRange(items.ToArray());
133 Status = "";
134 Progress = 0;
135 return;
136 }
137 }
138 }
139 }
140 public static Bitmap PixbufToBitmap(Pixbuf pixbuf)
141 {
142 if (pixbuf == null)
143 throw new ArgumentNullException(nameof(pixbuf), "Pixbuf cannot be null.");
144
145 // Get Pixbuf properties
146 int width = pixbuf.Width;
147 int height = pixbuf.Height;
148 int rowstride = pixbuf.Rowstride;
149 bool hasAlpha = pixbuf.HasAlpha;
150 byte[] pixelData = pixbuf.PixelBytes.Data;
151
152 // Create a Bitmap
153 PixelFormat pixelFormat = hasAlpha ? PixelFormat.Format32bppArgb : PixelFormat.Format24bppRgb;
154 Bitmap bitmap = new Bitmap(width, height, pixelFormat);
155
156 // Lock the Bitmap's data
157 BitmapData bmpData = bitmap.LockBits(
158 new Rectangle(0, 0, width, height),
159 ImageLockMode.WriteOnly,
160 pixelFormat);
161
162 // Copy pixel data
163 IntPtr bmpPtr = bmpData.Scan0;
164 unsafe
165 {
166 byte* srcPtr = (byte*)pixbuf.Pixels;
167 byte* destPtr = (byte*)bmpPtr;
168
169 for (int y = 0; y < height; y++)
170 {
171 byte* srcRow = srcPtr + y * rowstride;
172 byte* destRow = destPtr + y * bmpData.Stride;
173
174 if (hasAlpha)
175 {
176 for (int x = 0; x < width; x++)
177 {
178 destRow[x * 4 + 0] = srcRow[x * 4 + 2]; // B
179 destRow[x * 4 + 1] = srcRow[x * 4 + 1]; // G
180 destRow[x * 4 + 2] = srcRow[x * 4 + 0]; // R
181 destRow[x * 4 + 3] = srcRow[x * 4 + 3]; // A
182 }
183 }
184 else
185 {
186 for (int x = 0; x < width; x++)
187 {
188 destRow[x * 3 + 0] = srcRow[x * 3 + 2]; // B
189 destRow[x * 3 + 1] = srcRow[x * 3 + 1]; // G
190 destRow[x * 3 + 2] = srcRow[x * 3 + 0]; // R
191 }
192 }
193 }
194 }
195
196 // Unlock and return the Bitmap
197 bitmap.UnlockBits(bmpData);
198 return bitmap;
199 }
200
201 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
202 {
203 if (listView1.SelectedIndices.Count <= 0)
204 return;
205 string[] f = listView1.SelectedItems[0].Text.Split(' ');
206 BioImage b = BioLib.OMERO.GetImage(f[0], datas[selectedIndex].getId());
208 }
209
210 private void searchBox_TextChanged(object sender, EventArgs e)
211 {
212 listView1.Items.Clear();
213 List<ListViewItem> list = new List<ListViewItem>();
214 foreach (ListViewItem item in items)
215 {
216 if(item.Text.Contains(searchBox.Text))
217 list.Add(item);
218 }
219 listView1.Items.AddRange(list.ToArray());
220 }
221 }
222}
AForge.Bitmap Bitmap
AForge.Rectangle Rectangle
System.Drawing.Graphics Graphics
Definition OMERO.cs:14
BioLib.OMERO OMERO
Definition OMERO.cs:16
AForge.PixelFormat PixelFormat
BioLib.BioImage BioImage
Definition TabsView.cs:15
static TabsView tabsView
Definition App.cs:16
static int port
Definition Login.cs:16
static string password
Definition Login.cs:15
static string username
Definition Login.cs:15
static string host
Definition Login.cs:15
List< omero.gateway.model.DatasetData > datas
Definition OMERO.cs:22
static Bitmap PixbufToBitmap(Pixbuf pixbuf)
Definition OMERO.cs:140
int selectedIndex
Definition OMERO.cs:24
string Status
Definition OMERO.cs:38
void AddTab(BioImage b)
Definition TabsView.cs:134