2using System.Collections.Generic;
3using System.ComponentModel;
6using System.Drawing.Imaging;
9using System.Threading.Tasks;
10using System.Windows.Forms;
16using System.Runtime.InteropServices;
19 public partial class OMERO : Form
21 public List<omero.gateway.model.DatasetData>
datas =
new List<omero.gateway.model.DatasetData>();
22 private List<ListViewItem> items =
new List<ListViewItem>();
24 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
27 get {
return progressBar.Value; }
31 progressBar.Value = value;
35 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
38 get {
return statusLabel.Text; }
39 set { statusLabel.Text = value; }
43 InitializeComponent();
45 if (log.ShowDialog() == DialogResult.OK)
53 BioLib.OMERO.ReConnect();
54 var dst = BioLib.OMERO.GetDatasetsData();
56 foreach (var src
in dst)
60 comboBox1.Items.Add(src.getName() +
" " + src.getId());
66 IntPtr hIcon = bmp.GetHicon();
67 return Icon.FromHandle(hIcon);
69 public static System.Drawing.Bitmap
RawBytesToBitmap(
byte[] rawData,
int width,
int height, System.Drawing.Imaging.PixelFormat pixelFormat)
71 int bytesPerPixel =
Image.GetPixelFormatSize(pixelFormat) / 8;
72 int stride = width * bytesPerPixel;
74 System.Drawing.Bitmap bmp =
new System.Drawing.Bitmap(width, height, pixelFormat);
77 System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(
78 new System.Drawing.Rectangle(0, 0, width, height),
79 (ImageLockMode)ImageLockMode.WriteOnly,
82 IntPtr ptr = bmpData.Scan0;
85 if (bmpData.Stride == stride)
87 Marshal.Copy(rawData, 0, ptr, rawData.Length);
92 for (
int y = 0; y < height; y++)
94 int srcOffset = y * stride;
95 int destOffset = y * bmpData.Stride;
96 Marshal.Copy(rawData, srcOffset, ptr + destOffset, stride);
100 bmp.UnlockBits(bmpData);
103 private void comboBox1_SelectedIndexChanged(
object sender, EventArgs e)
105 listView1.Items.Clear();
107 string[] sts = comboBox1.SelectedItem.ToString().Split(
" ");
108 List<ListViewItem> lss =
new List<ListViewItem>();
109 foreach (omero.gateway.model.DatasetData s in
datas)
111 if (s.getId().ToString() == sts[1].ToString())
113 Status =
"Getting dataset information.";
114 List<string> fs =
new List<string>();
115 List<long> ids = BioLib.OMERO.GetDatasetIds(s.getId());
116 foreach (
long id in ids)
118 fs.Add(BioLib.OMERO.GetNameFromID(
id));
120 if (loadIconsBox.Checked)
122 Status =
"Loading icons...";
124 ImageList ims =
new ImageList
126 ImageSize =
new System.Drawing.Size(64, 64),
127 ColorDepth = ColorDepth.Depth32Bit
129 Dictionary<long, Pixbuf> dict = BioLib.OMERO.GetThumbnails(fs.ToArray(), 64, 64);
131 Status =
"Loading files...";
132 foreach (var item
in ids)
134 foreach (var itm
in dict)
140 ListViewItem li =
new ListViewItem();
144 Progress = (int)(((
float)(i + 1) / (
float)(ids.Count)) * 100);
149 listView1.SmallImageList = ims;
150 listView1.LargeImageList = ims;
151 listView1.View = View.LargeIcon;
152 listView1.Items.AddRange(items.ToArray());
159 Status =
"Loading files...";
161 foreach (var item
in ids)
163 ListViewItem li =
new ListViewItem();
166 Progress = (int)(((
float)(i + 1) / (
float)(ids.Count)) * 100);
169 listView1.View = View.List;
170 listView1.Items.AddRange(items.ToArray());
181 throw new ArgumentNullException(nameof(pixbuf),
"Pixbuf cannot be null.");
184 int width = pixbuf.Width;
185 int height = pixbuf.Height;
186 int rowstride = pixbuf.Rowstride;
187 bool hasAlpha = pixbuf.HasAlpha;
188 byte[] pixelData = pixbuf.PixelBytes.Data;
191 System.Drawing.Imaging.PixelFormat pixelFormat = hasAlpha ? System.Drawing.Imaging.PixelFormat.Format32bppArgb : System.Drawing.Imaging.PixelFormat.Format24bppRgb;
192 System.Drawing.Bitmap bitmap =
new System.Drawing.Bitmap(width, height, pixelFormat);
195 System.Drawing.Imaging.BitmapData bmpData = bitmap.LockBits(
196 new System.Drawing.Rectangle(0, 0, width, height),
197 (System.Drawing.Imaging.ImageLockMode)ImageLockMode.WriteOnly,
198 (System.Drawing.Imaging.PixelFormat)pixelFormat);
201 IntPtr bmpPtr = bmpData.Scan0;
204 byte* srcPtr = (
byte*)pixbuf.Pixels;
205 byte* destPtr = (
byte*)bmpPtr;
207 for (
int y = 0; y < height; y++)
209 byte* srcRow = srcPtr + y * rowstride;
210 byte* destRow = destPtr + y * bmpData.Stride;
214 for (
int x = 0; x < width; x++)
216 destRow[x * 4 + 0] = srcRow[x * 4 + 2];
217 destRow[x * 4 + 1] = srcRow[x * 4 + 1];
218 destRow[x * 4 + 2] = srcRow[x * 4 + 0];
219 destRow[x * 4 + 3] = srcRow[x * 4 + 3];
224 for (
int x = 0; x < width; x++)
226 destRow[x * 3 + 0] = srcRow[x * 3 + 2];
227 destRow[x * 3 + 1] = srcRow[x * 3 + 1];
228 destRow[x * 3 + 2] = srcRow[x * 3 + 0];
235 bitmap.UnlockBits(bmpData);
239 private void listView1_SelectedIndexChanged(
object sender, EventArgs e)
241 if (listView1.SelectedIndices.Count <= 0)
243 string[] f = listView1.SelectedItems[0].Text.Split(
' ');
248 private void searchBox_TextChanged(
object sender, EventArgs e)
250 listView1.Items.Clear();
251 List<ListViewItem> list =
new List<ListViewItem>();
252 foreach (ListViewItem item
in items)
254 if(item.Text.Contains(searchBox.Text))
257 listView1.Items.AddRange(list.ToArray());
System.Drawing.Image Image
System.Drawing.Graphics Graphics
List< omero.gateway.model.DatasetData > datas
static System.Drawing.Bitmap RawBytesToBitmap(byte[] rawData, int width, int height, System.Drawing.Imaging.PixelFormat pixelFormat)
static Icon BytesToIcon(System.Drawing.Bitmap bmp)
static System.Drawing.Bitmap PixbufToBitmap(Pixbuf pixbuf)