async void GetUserInfo() { var plist = NSUserDefaults.StandardUserDefaults; string userId = plist.StringForKey("userId"); userRepository = new UsersRepository(); user = userRepository.GetUser(userId); if (!user.Any()) { Console.WriteLine("User does not exist"); LoadingOverlay.RemoveOverlay(); return; } if (user.First().Avatar != null && user.First().Avatar.Length > 0) { profileImage = await ConvertImage.ConvertBinaryToImage(user.First().Avatar); } else { profileImage = null; } userInfoTableView.Source = new UserProfileTableSource(userProfileTableItems, user.First(), profileImage, this); userInfoTableView.ReloadData(); LoadingOverlay.RemoveOverlay(); }
/// <summary> /// 清除取樣點 /// </summary> public void ClearPick() { _UseMap.SetAll(false); _PickInfos.Clear(); CurrentPickIndex = -1; int cot = BaseImage.PixelCount; IntPtr basePtr = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly); IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly); unsafe { byte *baseP = (byte *)basePtr.ToPointer(); byte *convertP = (byte *)convertPtr.ToPointer(); for (int i = 0; i < cot; i++) { byte v = (byte)((baseP[0] + baseP[1] + baseP[2]) / 3); convertP[0] = v; convertP[1] = v; convertP[2] = v; baseP += 4; convertP += 4; } } BaseImage.UnlockBits(); ConvertImage.UnlockBits(); }
protected void OnAddImageButtonClicked(object sender, EventArgs e) { if (Paused) { var type = ColonyTypeList.Active; if (type >= 0) { GtkSelection.Selected = 0; var Width = Math.Min(worldImage.WidthRequest, LoadedImage.Pixbuf.Width); var Height = Math.Min(worldImage.HeightRequest, LoadedImage.Pixbuf.Height); var neighborhood = SetNeighborhood(); var colony = ConvertImage.Convert(ColoniesType[type], LoadedImage, Width, Height, ColonyParameters, ColonyColor.Color, neighborhood, Cyclic.Active, Gradient.Active); // Cannot handle Add Image for Elementary CA (1D) if (!(colony is EmptyArtificialLife || colony is ElementaryCA)) { var count = GtkSelection.Selection.Count(); GtkSelection.Selection.Add(0, 0, colony.Width, colony.Height); if (GtkSelection.Selection.Count() > count) { Colonies.Add(new Colony(0, 0, colony)); } } Refresh(); } } }
private void btnAddPariente_Click(object sender, EventArgs e) { try { if (txtArchivo.Text == "") { RadMessageBox.Show("Selecciona un archivo antes de continuar", this.Text, MessageBoxButtons.OK, RadMessageIcon.Exclamation); return; } if (oList.FindAll(item => item.Documento.Id == int.Parse(cboDocs.SelectedValue.ToString()) && item.DatosUsuario.Estatus == true).Count == 0) { DigitalizadosDetalleBE oDetalle = new DigitalizadosDetalleBE(); oDetalle.Sel = false; oDetalle.Documento.Id = int.Parse(cboDocs.SelectedValue.ToString()); oDetalle.Documento.Nombre = cboDocs.SelectedItem.Text; oDetalle.RutaArchivo = path; oDetalle.NombreArchivo = System.IO.Path.GetFileName(oDialog.FileName); oDetalle.RutaOriginal = oDialog.FileName; oDetalle.Archivo = ConvertImage.FileToByteArray(oDialog.FileName); oList.Add(oDetalle); ActualizaGrid(); txtArchivo.Text = string.Empty; } else { RadMessageBox.Show("No es posible agregar un tipo de documento o un archivo que ya existe en la lista", this.Text, MessageBoxButtons.OK, RadMessageIcon.Info); } } catch (Exception ex) { RadMessageBox.Show("Ocurrió un error al agregar el archivo\n" + ex.Message, this.Text, MessageBoxButtons.OK, RadMessageIcon.Error); } }
public ucFood(Food f) { InitializeComponent(); food = f; lbFoodName.Text = f.Name; pbFoodImage.Image = ConvertImage.ByteArrayToImage(food.Content); }
private void btnImagen_Click(object sender, EventArgs e) { OpenFileDialog oDialog = new OpenFileDialog(); try { oDialog.Filter = "Archivos jpg (*.jpg)|*.jpg"; oDialog.Title = "Imagen de Producto"; if (oDialog.ShowDialog() == DialogResult.OK) { System.IO.FileInfo oFile = new System.IO.FileInfo(oDialog.FileName); if (oFile.Length > 200000) { RadMessageBox.Show("La imagen debe no debe ser mayor a 200Kb", this.Text, MessageBoxButtons.OK, RadMessageIcon.Info); } else { Imagen = ConvertImage.FileToByteArray(oDialog.FileName); picFoto.Image = ConvertImage.ByteToImage(Imagen); } } } catch (Exception ex) { RadMessageBox.Show("Ocurrió un error al cargar la fotografía del expediente\n" + ex.Message, this.Text, MessageBoxButtons.OK, RadMessageIcon.Error); } }
private void buttonConvert_Click(object sender, EventArgs e) { Bitmap input = new Bitmap(textBoxInput.Text); Bitmap output = ConvertImage.ConvertTo1Bit(input); output.Save(textBoxOutput.Text); }
public ActionResult SomeAction() { ConvertImage convert = new ConvertImage(); convert.base64ToImage("SomeValue"); return(View()); }
/// <summary> /// Converts an image to IPictureDisp /// </summary> /// <param name="image">target image to convert</param> /// <returns>IPictureDisp instance</returns> public stdole.IPictureDisp ToPicture(Image image) { if (null == image) { throw new ArgumentNullException("image"); } return(ConvertImage.Convert(image)); }
/// <summary> /// 使用採樣暫存地圖調整主要採樣點的數值 /// </summary> public void CurrentValueSet(int allowance, int range) { if (CurrentPickIndex >= _PickInfos.Count || CurrentPickIndex < 0) { return; } Pick currentPick = _PickInfos[CurrentPickIndex]; int oldAllowance = currentPick.Allowance; int oldRange = currentPick.Range; currentPick.Allowance = allowance; currentPick.Range = range; if (oldAllowance == currentPick.Allowance && oldRange == currentPick.Range) { return; } int cot = BaseImage.PixelCount; IntPtr basePtr = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly); IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly); unsafe { byte *baseP = (byte *)basePtr.ToPointer(); byte *convertP = (byte *)convertPtr.ToPointer(); for (int i = 0; i < cot; i++) { if (_ColorMap[i] <= currentPick.Allowance && _DistanceMap[i] <= currentPick.Range) { if (!_UseMap[i] && !currentPick.UseMap[i]) { convertP[0] = baseP[0]; convertP[1] = baseP[1]; convertP[2] = baseP[2]; } currentPick.UseMap[i] = true; } else { if (!_UseMap[i] && currentPick.UseMap[i]) { byte v = (byte)((baseP[0] + baseP[1] + baseP[2]) / 3); convertP[0] = v; convertP[1] = v; convertP[2] = v; } currentPick.UseMap[i] = false; } baseP += 4; convertP += 4; } } BaseImage.UnlockBits(); ConvertImage.UnlockBits(); }
private bool disposedValue = false; // 偵測多餘的呼叫 protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { ConvertImage.Dispose(); } disposedValue = true; } }
public bool UpdateImage(Image img) { try { return(Network.SendImage(DataClient.Email, DataClient.Token, ConvertImage.ImageToByteArray(img))); } catch (Exception) { return(false); } }
public void Template2() { var tbytes = File.ReadAllBytes("2_template.bmp"); ConvertImage ci = new ConvertImage(new[] { "0_TRLSHAMN_" }); ci.Execute(); var bytes = File.ReadAllBytes("2.bmp"); AssertEquality(tbytes, bytes); }
public Image AskImage(string email) { try { return(ConvertImage.ByteArrayToImage(Network.GetImage(email, DataClient.Token))); } catch (Exception) { return(null); } }
protected async override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); try { var continueArgs = args as FileOpenPickerContinuationEventArgs; if (continueArgs != null && continueArgs.Files.Any()) { switch (OpenFilePickerReason) { case OpenFilePickerReason.OnOpeningVideo: if (Window.Current.Content == null) { await LaunchTheApp(); } await Locator.MediaPlaybackViewModel.OpenFile(continueArgs.Files[0]); break; case OpenFilePickerReason.OnOpeningSubtitle: { string mru = StorageApplicationPermissions.FutureAccessList.Add(continueArgs.Files[0]); string mrl = "winrt://" + mru; Locator.MediaPlaybackViewModel.OpenSubtitle(mrl); } break; case OpenFilePickerReason.OnPickingAlbumArt: if (continueArgs.Files == null) { return; } var file = continueArgs.Files.First(); if (file == null) { return; } var byteArray = await ConvertImage.ConvertImagetoByte(file); await App.MusicMetaService.SaveAlbumImageAsync(SelectedAlbumItem, byteArray); await Locator.MusicLibraryVM._albumDatabase.Update(SelectedAlbumItem); SelectedAlbumItem = null; break; } } OpenFilePickerReason = OpenFilePickerReason.Null; } catch (Exception e) { ExceptionHelper.CreateMemorizedException("App.cs.OnActivated", e); } }
// Occurs when an image has been acquired and is ready to be processed. private void OnImageGrabbed(Object sender, ImageGrabbedEventArgs e) { try { // Acquire the image from the camera. Only show the latest image. The camera may acquire images faster than the images can be displayed. // Get the grab result. IGrabResult grabResult = e.GrabResult; // Check if the image can be displayed. if (grabResult.GrabSucceeded) { Bitmap bitmap = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format32bppRgb); // Lock the bits of the bitmap. BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); // Place the pointer to the buffer of the bitmap. converter.OutputPixelFormat = PixelType.BGRA8packed; IntPtr ptrBmp = bmpData.Scan0; converter.Convert(ptrBmp, bmpData.Stride * bitmap.Height, grabResult); bitmap.UnlockBits(bmpData); //UI thread에 접근하기 위해 dispatcher 사용 dispatcher.BeginInvoke((Action)(() => { CameraImage = ConvertImage.BitmapToImageSource(bitmap); })); FrameRate = Param.ResultingFrameRateAbs; if (IsImageSaveAuto == true) { Image_Save(); } /* * dispatcher.BeginInvoke((Action)(() => * { * CameraImageComplete(); * })); */ } } catch (Exception exception) { Log.Set(string.Format("Exception: {0}", exception.Message)); } finally { // Dispose the grab result if needed for returning it to the grab loop. e.DisposeGrabResultIfClone(); } }
/// <summary> /// 增加取樣點並設定容許值及範圍 /// </summary> public void AddPick(Color color, Point pickPoint, int allowance, int range) { Pick newPick = new Pick() { Allowance = allowance, Range = range, PickPoint = pickPoint, DisplayPoint = new Point((int)(pickPoint.X * _DisplayScale), (int)(pickPoint.Y * _DisplayScale)), Color = color, UseMap = new BitArray(ConvertImage.PixelCount) }; _PickInfos.Add(newPick); int cot = BaseImage.PixelCount; IntPtr basePtr = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly); IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly); unsafe { byte * baseP = (byte *)basePtr.ToPointer(); byte * convertP = (byte *)convertPtr.ToPointer(); double maxDistance = MaxRange / BaseImage.MaxDistance; int i = 0; for (int y = 0; y < BaseImage.Height; y++) { for (int x = 0; x < BaseImage.Width; x++) { byte r = baseP[2]; byte g = baseP[1]; byte b = baseP[0]; int dR = Math.Abs(newPick.Color.R - r); int dG = Math.Abs(newPick.Color.G - g); int dB = Math.Abs(newPick.Color.B - b); short c = (byte)Math.Max(Math.Max(dR, dG), dB); short d = (short)(Function.GetDistance(x, y, newPick.PickPoint.X, newPick.PickPoint.Y) * maxDistance); if (c <= newPick.Allowance && d <= newPick.Range) { convertP[0] = baseP[0]; convertP[1] = baseP[1]; convertP[2] = baseP[2]; newPick.UseMap[i] = true; } baseP += 4; convertP += 4; i++; } } } BaseImage.UnlockBits(); ConvertImage.UnlockBits(); }
static void Main(string[] args) { string url = "E:/Img/Prueba.jpg"; if (File.Exists(url)) { ConvertImage convertImage = new ConvertImage(); string image = convertImage.ConvertWebp(url, 1024, 1024); string baseImage = $"data: image/jpeg; base64, {image}"; convertImage = null; } }
public FileContentResult CommentUserImage(string id) { var image = this.images.GetUserImageById(id); if (image == null) { var file = ConvertImage.ToBytes("/Images/default-user-img.jpg"); return(this.File(file, "image/jpg")); } return(this.File(image.Content, "image/" + image.FileExtension)); }
public void Send() { _messageContent.MessageText = SendText; _messageContent.MessageTime = DateTime.Now.ToShortTimeString(); _messageContent.MessageColour = SenderReceiwer.Send; if (!_messageContent.PictureChanged) { _messageContent.MessagePicture = UserGender.GetUserGender(); } _messageContent.Name = UserInfo.Name; _messageContent.Id = User.Id; if (UserInfo.AddedPicture != null) { _messageContent.Pic = ConvertImage.ToByte(UserInfo.AddedPicture); _messageContent.MessagePicture = @"C:\Users\X\Downloads\ChatData\ChatImage" + _messageContent.Id + ".jpg"; _messageContent.PictureChanged = true; } var messageInBytes = ConverData.ToSend(_messageContent); try { TcpSocket.tcpSocket.BeginSend(messageInBytes, 0, messageInBytes.Length, SocketFlags.None, new AsyncCallback(SendCallback), TcpSocket.tcpSocket); } catch (Exception ex) { AlertMessages.Show(ex.Message); OnlineUsers.UserList.Clear(); TcpSocket.tcpSocket.Shutdown(SocketShutdown.Both); TcpSocket.tcpSocket.Disconnect(true); _windowsViewModel.ChangeView(0); return; } SendText = ""; UserInfo.AddedPicture = null; _messageContent.Pic = null; }
private void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { // If it's image (not a video) if (e.Info[UIImagePickerController.MediaType].ToString() == "public.image") { var editedImage = e.Info[UIImagePickerController.EditedImage] as UIImage; if (editedImage != null) { SharedImage = ConvertImage.MaxResizeImage(editedImage, 400, 400); GetTableViewData(User, SharedImage, this); } } imagePicker.DismissViewControllerAsync(true); }
private stdole.IPictureDisp getImage() { stdole.IPictureDisp tempImage = null; try { System.Drawing.Icon newIcon = Properties.Resources.MedPC; ImageList newImageList = new ImageList(); newImageList.Images.Add(newIcon); tempImage = ConvertImage.Convert(newImageList.Images[0]); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(tempImage); }
private Byte[] ObtenerImagen(int Expediente) { byte[] Foto; string Imagen = RutaImagen + Expediente.ToString() + ".png";; try { if (File.Exists(Imagen)) { Foto = ConvertImage.FileToByteArray(Imagen); } else { Foto = null; } } catch (Exception ex) { throw new Exception("Error al intentar guardar el archivo.", ex); } return(Foto); }
public async override void Execute(object parameter) { var album = parameter as AlbumItem; if (album == null) { var args = parameter as ItemClickEventArgs; if (args != null) { album = args.ClickedItem as AlbumItem; } } var openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".gif"); // Windows Phone launches the picker, then freezes the app. We need // to pick it up again on OnActivated. #if WINDOWS_PHONE_APP App.OpenFilePickerReason = OpenFilePickerReason.OnPickingAlbumArt; App.SelectedAlbumItem = album; openPicker.PickSingleFileAndContinue(); #else var file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } var byteArray = await ConvertImage.ConvertImagetoByte(file); await App.MusicMetaService.SaveAlbumImageAsync(album, byteArray); await Locator.MusicLibraryVM._albumDatabase.Update(album); #endif }
/// <summary> /// Get an image /// </summary> /// <param name="control">An IRibbonControl instance</param> /// <returns>IPictureDisp object</returns> public virtual stdole.IPictureDisp GetImage(Office.IRibbonControl control) { Assembly asm = Assembly.GetExecutingAssembly(); Stream stream = null; foreach (string name in asm.GetManifestResourceNames()) { if (name.EndsWith("OdfLogo.png")) { stream = asm.GetManifestResourceStream(name); break; } } if (stream == null) { return(null); } System.Drawing.Bitmap image = new System.Drawing.Bitmap(stream); return(ConvertImage.Convert(image)); }
private void ObtenerArchivos(int Expediente, ref List <DigitalizadosDetalleBE> oList) { string Ruta = RutaDoctos + Expediente.ToString() + "\\"; try { if (!Directory.Exists(Ruta)) { Directory.CreateDirectory(Ruta); } DirectoryInfo Dir = new DirectoryInfo(Ruta); foreach (var fi in Dir.GetFiles()) { var file = oList.Find(item => item.NombreArchivo == fi.Name); file.Archivo = ConvertImage.FileToByteArray(Ruta + fi.Name); } } catch (Exception ex) { throw new Exception("Error al intentar guardar el archivo.", ex); } }
private void btnAddFood_Click(object sender, EventArgs e) { Food food = new Food(); food.Name = tbFoodName.Text; float price; if (float.TryParse(tbFoodPrice.Text, out price)) { food.Price = price; } ; food.FoodCategoryId = (cbbFoodCate.SelectedItem as dynamic).Value; food.Content = ConvertImage.ImageToByteArray(pbFoodImage.Image); using (var DbContext = new AppContext()) { DbContext.Foods.Add(food); DbContext.SaveChanges(); } LoadFood(); ResetFoodData(); }
public void KrakenClient_CustomRequestConvertImageFormatEmptyConstructor_IsTrue() { var krakenClient = HelperFunctions.CreateWorkingClient(); var convertImage = new ConvertImage() { BackgroundColor = "#ffffff", Format = ImageFormat.gif }; var request = new OptimizeWaitRequest(new Uri(TestData.ImageOne)) { ConvertImage = convertImage }; var response = krakenClient.OptimizeWait(request); var result = response.Result; Assert.IsTrue(result.Body != null); Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl)); Assert.IsTrue(result.Body.KrakedUrl.EndsWith(".gif")); }
private async void ChangeBackground_OnClicked(object sender, RoutedEventArgs e) { var openPicker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".gif"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file == null) { return; } try { IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); BitmapImage bitmapImage = new BitmapImage(); ImageBrush brush = new ImageBrush(); await bitmapImage.SetSourceAsync(stream); brush.ImageSource = bitmapImage; brush.Stretch = Stretch.None; App.RootFrame.Background = brush; var img = await ConvertImage.ConvertImagetoByte(file); await ImageTools.SaveWallpaper(img); } catch (Exception ex) { var msgDlg = new MessageDialog("Something went wrong settings the background. :-(."); msgDlg.ShowAsync(); } }
/// <summary> /// 刪除取樣點 /// </summary> /// <param name="removePickIndex">移除取樣點索引</param> public void RemovePick(int removePickIndex) { if (removePickIndex >= _PickInfos.Count || removePickIndex < 0) { return; } Pick removePick = _PickInfos[removePickIndex]; _PickInfos.Remove(removePick); CurrentPickIndex = -1; int cot = ConvertImage.PixelCount; BitArray useMap = new BitArray(cot); foreach (Pick pick in _PickInfos) { useMap.Or(pick.UseMap); } IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly); unsafe { byte *convertP = (byte *)convertPtr.ToPointer(); for (int i = 0; i < cot; i++) { if (removePick.UseMap[i] && !useMap[i]) { byte v = (byte)((convertP[0] + convertP[1] + convertP[2]) / 3); convertP[0] = v; convertP[1] = v; convertP[2] = v; } convertP += 4; } } ConvertImage.UnlockBits(); }