void RotatePicture(System.Drawing.RotateFlipType rotateType) { string sPicturePath = ViewState["sPicturePath"] as string; if (null == sPicturePath) { return; } System.Drawing.Image image = null; string imageFileName = Server.MapPath(sPicturePath); try { image = System.Drawing.Image.FromFile(imageFileName); image.RotateFlip(rotateType); image.Save(imageFileName); //Response.Redirect(Request.QueryString["r"]); Image1.ImageUrl = "ShrinkImage.aspx?i=" + sPicturePath + "&w=900"; } finally { if (null != image) { image.Dispose(); } } }
public void Save(System.Drawing.Bitmap bm, string filename, System.Drawing.RotateFlipType rotate) { Bitmap image = bm; if (rotate != RotateFlipType.RotateNoneFlipNone) { image.RotateFlip(rotate); } using (FileStream stream = new FileStream(filename, FileMode.Create)) { using (iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN)) { iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream); pdfDocument.Open(); MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms); img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN)); pdfDocument.Add(img); pdfDocument.Close(); writer.Close(); } } }
private void RotateFlip(System.Drawing.RotateFlipType type) { manager.AddAction(type.ToString(), imgPicture.Source as BitmapFrame); imgPicture.Source = BitmapFrame.Create( (imgPicture.Source as BitmapFrame).RotateFlip(type)); UpdatePreviewImages(); }
public static T FromRotateFlipType(RotateFlipType value) { return(new T(0x53427160 >> ((byte)value << 2) & 7)); /*// * byte v = (byte)value; * return new T((v << 2 & 4) ^ (v << 1 & 2) ^ (v >> 1)); * //*/ }
public static T GetInverseElement(this T _this) { byte t = (byte)_this; return((T)(0x76541230 >> (t << 2) & 7)); /*// * return (T)(((t >> 2 ^ 1) & t) << 1 ^ t); * //*/ }
public static int GetCycleLength(this T _this) { return(0x22224241 >> ((byte)_this << 2) & 7); /*// * return 1 << (0x5598 >> ((byte)_this << 1) & 3); * byte t = (byte)_this; * return 1 << (20 >> t & 3 | (t >> 2)); * //*/ }
void Flip(System.Drawing.RotateFlipType type) { var bitmap = Coder.StringToBitmap(AllText); bitmap.RotateFlip(type); Replace(new List <Range> { FullRange }, new List <string> { Coder.BitmapToString(bitmap) }); SetSelections(new List <Range> { BeginRange }); }
/// <summary> /// /// </summary> /// <param name="texture"></param> /// <param name="sourceModification"></param> /// <param name="destination"></param> public void BakeTexture(Texture2D texture, System.Drawing.RotateFlipType sourceModification, Rectangle destination) { Stream sourceBuffer = new MemoryStream(); texture.SaveAsPng(sourceBuffer, texture.Width, texture.Height); System.Drawing.Image sourceImage = System.Drawing.Image.FromStream(sourceBuffer); sourceBuffer = new MemoryStream(); sourceImage.RotateFlip(sourceModification); sourceImage.Save(sourceBuffer, System.Drawing.Imaging.ImageFormat.Png); _batch.Draw( Texture2D.FromStream(_graphicsDevice, sourceBuffer), destination, Color.White); }
/// <summary> /// 转换Bitmap到Image(WPF) /// </summary> public static BitmapImage ConvertBitmapToSource(System.Drawing.Bitmap b, System.Drawing.RotateFlipType t = System.Drawing.RotateFlipType.Rotate90FlipX) { b.RotateFlip(t); MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); BitmapImage bmi = new BitmapImage(); bmi.BeginInit(); bmi.StreamSource = new MemoryStream(ms.ToArray()); bmi.EndInit(); ms.Close(); return(bmi); }
private int GetBitmapRotationAngleByRotationFlipType(System.Drawing.RotateFlipType rotationFlipType) { switch (rotationFlipType) { case System.Drawing.RotateFlipType.RotateNoneFlipNone: default: return(0); case System.Drawing.RotateFlipType.Rotate90FlipNone: return(90); case System.Drawing.RotateFlipType.Rotate180FlipNone: return(180); case System.Drawing.RotateFlipType.Rotate270FlipNone: return(270); } }
public static void TextureGl(TextureTarget t, string file, System.Drawing.RotateFlipType r = System.Drawing.RotateFlipType.RotateNoneFlipY) { System.Drawing.Bitmap b = new System.Drawing.Bitmap(file); b.RotateFlip(r); System.Drawing.Imaging.BitmapData data = b.LockBits(new System.Drawing.Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Gl.PixelStoref(PixelStoreParameter.PackAlignment, 1); Gl.TexImage2D(t, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); b.UnlockBits(data); Gl.GenerateMipmap(GenerateMipmapTarget.Texture2D); Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureParameter.LinearMipMapLinear); Gl.TexParameterf(TextureTarget.Texture2D, TextureParameterName.TextureLodBias, 0); if (Gl.IsExtensionSupported(Extension.GL_EXT_texture_filter_anisotropic)) { Gl.TexParameterf(TextureTarget.Texture2D, TextureParameterName.MaxAnisotropyExt, Math.Min(4f, Gl.GetFloat(GetPName.MaxTextureMaxAnisotropyExt))); } }
public void Add(System.Drawing.Bitmap bm, System.Drawing.RotateFlipType rotate) { if (this.stream == null) { this.stream = new FileStream(this.FileName, FileMode.Create); this.pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN); this.writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream); this.pdfDocument.Open(); } Bitmap image = bm; if (rotate != RotateFlipType.RotateNoneFlipNone) { image.RotateFlip(rotate); } { iTextSharp.text.Image img = getImage(image); img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN)); pdfDocument.Add(img); } }
bool isStop = false; //接ProcessingDialog 回傳值 停止 private void ToggleButton_WifiImport_Click(object sender, RoutedEventArgs e) { ToggleButton toggleButton = (ToggleButton)sender; if (toggleButton.IsChecked == true) { if (!string.IsNullOrEmpty(Agencys.Agency_WifiCardPath)) { if (Directory.Exists(Agencys.Agency_WifiCardPath)) { //讀寫Registrations //確認掛號資料 DateTime RegistrationDate = mwvm.SelectedDate; int Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, RegistrationDate); processingDialog = new ProcessingDialog(); Task task = Task.Factory.StartNew(() => { processingDialog.Dispatcher.Invoke(() => { processingDialog.PText = "圖片偵測中"; processingDialog.PIsIndeterminate = true; processingDialog.ButtonContentVisibility = Visibility.Hidden; processingDialog.ReturnValueCallback += new ProcessingDialog.ReturnValueDelegate(this.SetReturnValueCallbackFun); processingDialog.Show(); }); int imageCount = 0; while (true) { //偵測資料夾 foreach (string f in Directory.GetFiles(Agencys.Agency_WifiCardPath)) { Thread.Sleep(500); pf = new PatientsFolder(Agencys, Patients, RegistrationDate); if (!Directory.Exists(pf.PatientFullFolderPath)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); } string extension = Path.GetExtension(f).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //System.Drawing.RotateFlipType rft = ImageHelper.RotateImageByExifOrientationData(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension), true); ////複製原圖到目的Original //File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); // Rotate the image according to EXIF data var bmp = new System.Drawing.Bitmap(f); System.Drawing.RotateFlipType fType = ImageHelper.RotateImageByExifOrientationData(bmp, true); if (fType != System.Drawing.RotateFlipType.RotateNoneFlipNone) { bmp.Save(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension)); } else { File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); } string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 ImageInfo importImage = dbi.InsertImageReturnImageInfo(imagePath, imageFileName, imageSize, imageExtension, Registration_ID, RegistrationDate, Agencys.Agency_ImagePath, 800); File.Delete(f); //加入showImage清單 mwvm.ShowImages.Add(importImage); //已匯入 imageCount++; processingDialog.Dispatcher.Invoke(() => { processingDialog.PText = "圖片匯入中,已匯入" + imageCount + "張"; }); } //按停止 if (isStop) { isStop = false; return; } } }).ContinueWith(cw => { //結束 processingDialog.PText = "處理完畢"; processingDialog.Close(); toggleButton.IsChecked = false; ReloadRegistration(Registration_ID, RegistrationDate); GC.Collect(); }, TaskScheduler.FromCurrentSynchronizationContext()); } else { MessageBox.Show("Wifi Card實體資料夾位置尚未建立", "提示", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("尚未設置Wifi Card資料夾位置", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private void Button_Import_Click(object sender, RoutedEventArgs e) { Button btnImport = (Button)sender; btnImport.IsEnabled = false; btnImport.Refresh(); OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true, DefaultExt = ".png", Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif" }; bool?ofdResult = ofd.ShowDialog(); if (ofdResult.HasValue && ofdResult.Value)//OpenFileDialog 選確定 { if (Directory.Exists(Agencys.Agency_ImagePath)) { //讀寫Registrations //確認掛號資料 DateTime RegistrationDate = mwvm.SelectedDate; int Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, RegistrationDate); pf = new PatientsFolder(Agencys, Patients, RegistrationDate); #region 小圖路徑(未使用) ////..\病患資料夾\掛號日期\Small //string PatientFolderPathSmall = pf.PatientFolderPathSmall; ////Agencys_ImagePath\病患資料夾\掛號日期\Small //string PatientFullFolderPathSmall = pf.PatientFullFolderPathSmall; #endregion if (!Directory.Exists(pf.PatientFullFolderPathOriginal)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); //Directory.CreateDirectory(PatientFullFolderPathSmall); } pd = new ProgressDialog(); pd.Dispatcher.Invoke(() => { pd.PMinimum = 0; pd.PValue = 0; pd.PMaximum = ofd.FileNames.Count(); pd.PText = "圖片匯入中,請稍後( 0" + " / " + pd.PMaximum + " )"; pd.Show(); }); Task t = Task.Factory.StartNew(() => { foreach (string fileName in ofd.FileNames) { string extension = Path.GetExtension(fileName).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); //System.Drawing.RotateFlipType rft = ImageHelper.RotateImageByExifOrientationData(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension), true); ////複製原圖到目的Original //File.Copy(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); // Rotate the image according to EXIF data var bmp = new System.Drawing.Bitmap(fileName); System.Drawing.RotateFlipType fType = ImageHelper.RotateImageByExifOrientationData(bmp, true); if (fType != System.Drawing.RotateFlipType.RotateNoneFlipNone) { bmp.Save(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension)); } else { File.Copy(fileName, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); } string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 ImageInfo importImage = dbi.InsertImageReturnImageInfo(imagePath, imageFileName, imageSize, imageExtension, Registration_ID, RegistrationDate, Agencys.Agency_ImagePath, 800); //加入showImage清單 mwvm.ShowImages.Add(importImage); #region 產生小圖(未使用) //產生縮圖到Small //ImageProcess.SaveThumbPic(fileName, 300, PatientFullFolderPathSmall + @"\" + newFileName + @"sml" + extension); //寫資料庫 //dde.Images.Add(new Images //{ // Image_Path = @"\" + PatientFolderPathSmall + @"\" + newFileName + @"sml" + extension, // Image_FileName = newFileName + @"sml" + extension, // Image_Size = "Small", // Image_Extension = extension, // Registration_ID = Registration_ID //}); //dde.SaveChanges(); #endregion pd.Dispatcher.Invoke(() => { pd.PValue++; pd.PText = "圖片匯入中,請稍後( " + pd.PValue + " / " + pd.PMaximum + " )"; }); Thread.Sleep(200); } }).ContinueWith(cw => { pd.Dispatcher.Invoke(() => { pd.PText = "匯入完成"; pd.Close(); }); ReloadRegistration(Registration_ID, RegistrationDate); GC.Collect(); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } else { MessageBox.Show("影像資料夾有問題,請檢查設定是否有誤", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } btnImport.IsEnabled = true; btnImport.Refresh(); }
public static T Add(this T _this, T other) { byte t = (byte)_this, o = (byte)other; return((T)(((t >> 2 ^ t) & o & 1) << 1 ^ t ^ o)); }
public static T Compose(this T _this, T other) { byte t = (byte)_this, o = (byte)other; return((T)(((o >> 2 ^ o) & t & 1) << 1 ^ t ^ o)); }
/// <summary><return> /// <para>true for /// <para>Rotate90FlipX,</para> /// <para>Rotate270FlipY,</para> /// <para>Rotate90FlipY,</para> /// <para>Rotate270FlipX;</para> /// </para> /// <para>false for /// <para>RotateNoneFlipNone,</para> /// <para>Rotate180FlipXY,</para> /// <para>RotateNoneFlipXY,</para> /// <para>Rotate180FlipNone,</para> /// <para>RotateNoneFlipX,</para> /// <para>Rotate180FlipY,</para> /// <para>RotateNoneFlipY,</para> /// <para>Rotate180FlipX,</para> /// <para>Rotate90FlipNone,</para> /// <para>Rotate270FlipXY,</para> /// <para>Rotate270FlipNone,</para> /// <para>Rotate90FlipXY.</para> /// </para> /// </return></summary> public static bool IsDiagonalReflection(this T _this) { return((_this & T.Rotate90FlipX) == T.Rotate90FlipX); }
public static Image DrawImage(Rectangle rectangle, PdfCanvas canvas, string imagePath, System.Drawing.RotateFlipType rotateFlipType, bool scaleAbsolute, bool centerVertically, bool centerHorizontally) { using (var originalImage = System.Drawing.Image.FromFile(imagePath)) { originalImage.RotateFlip(rotateFlipType); using (var memoryStream = new MemoryStream()) { originalImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); var imageData = ImageDataFactory.Create(memoryStream.ToArray()); var image = new Image(imageData); if (scaleAbsolute) { image.ScaleAbsolute(rectangle.GetWidth(), rectangle.GetHeight()); } else { image.ScaleToFit(rectangle.GetWidth(), rectangle.GetHeight()); } var xOffset = centerHorizontally ? (rectangle.GetWidth() / 2 - image.GetImageScaledWidth() / 2) : 0; var yOffset = centerVertically ? (rectangle.GetHeight() / 2 - image.GetImageScaledHeight() / 2) : 0; var imageRectangle = new Rectangle( rectangle.GetX() + xOffset, rectangle.GetY() + yOffset, image.GetImageScaledWidth(), image.GetImageScaledHeight()); canvas.AddImageFittedIntoRectangle(imageData, imageRectangle, false); return(image); } } }
public void RotateFlip(System.Drawing.RotateFlipType rotateFlipType) { }
public static T Times(this T _this, int count) { byte t = (byte)_this; return((T)((count & 1) * t ^ ((t >> 1 ^ 2) & (t << 1) & count))); }
private void LoadImage(string filename) { FullScreenImage.RenderTransform = null; FullScreenImage.Visibility = Visibility.Visible; FullScreenMedia.Visibility = Visibility.Collapsed; try { using (FileStream imgStream = File.Open(filename, FileMode.Open, FileAccess.ReadWrite)) { if (Path.GetExtension(filename).ToLower() == ".jpg") // load exif only for jpg { StringBuilder info = new StringBuilder(); //var decoder = new JpegBitmapDecoder(imgStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); //var decoder = new JpegBitmapDecoder(imgStream, BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); BitmapDecoder decoder = BitmapDecoder.Create(imgStream, BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad); var bitmapFrame = decoder.Frames[0]; // create an encoder for the output file JpegBitmapEncoder output = new JpegBitmapEncoder(); if (bitmapFrame != null) { BitmapFrame frameCopy = (BitmapFrame)bitmapFrame.Clone(); BitmapMetadata metaData = (BitmapMetadata)bitmapFrame.Metadata.Clone(); info.AppendLine(filename + "\n" + (int)bitmapFrame.Width + "x" + (int)bitmapFrame.Height); if (metaData != null) { if (!String.IsNullOrWhiteSpace(metaData.DateTaken)) { info.AppendLine("Date taken: " + metaData.DateTaken); } if (!String.IsNullOrWhiteSpace(metaData.Title)) { info.AppendLine("Title: " + metaData.Title); } if (!String.IsNullOrWhiteSpace(metaData.Subject)) { info.AppendLine("Subject: " + metaData.Subject); } if (!String.IsNullOrWhiteSpace(metaData.Comment)) { info.AppendLine("User comment: " + metaData.Comment); } Console.WriteLine("Begin medatdata dump *******************************************"); //PrintMetadata(decoder.Frames[0].Metadata, string.Empty); Console.WriteLine("End medatdata dump *******************************************"); String xmpSubject = (String)metaData.GetQuery("/xmp/dc:subject/{ulong=0}"); UInt16 orient = 1; System.Drawing.RotateFlipType fType = System.Drawing.RotateFlipType.RotateNoneFlipNone; if (metaData.ContainsQuery(@"/app1/{ushort=0}/{ushort=274}")) { orient = (UInt16)metaData.GetQuery(@"/app1/{ushort=0}/{ushort=274}"); //get rotation fType = GetRotateFlipTypeByExifOrientationData(orient); } if (imageRotationAngle == 90) { orient = (UInt16)GetNextRotationOrientation(orient); // get new rotation //create keys if we dont have it yet if (!metaData.ContainsQuery("/app1")) { metaData.SetQuery("/app1", new BitmapMetadata("app1")); } if (!metaData.ContainsQuery("/app1/{ushort=0}")) { metaData.SetQuery("/app1/{ushort=0}", new BitmapMetadata("ifd")); } metaData.SetQuery("/app1/{ushort=0}/{ushort=274}", orient); //set next rotation fType = GetRotateFlipTypeByExifOrientationData(orient); var enc = new JpegBitmapEncoder(); //enc.Frames.Add(BitmapFrame.Create(bitmapFrame, bitmapFrame.Thumbnail, metaData, bitmapFrame.ColorContexts)); enc.Frames.Add(BitmapFrame.Create(frameCopy, frameCopy.Thumbnail, metaData, frameCopy.ColorContexts)); output.Frames.Add(BitmapFrame.Create(frameCopy, frameCopy.Thumbnail, metaData, null)); imgStream.Seek(0, SeekOrigin.Begin); //imgStream.SetLength(0); // clear all data enc.Save(imgStream); // finally, save the new file over the old file using (Stream outputFile = File.Open(filename + "_out.jpg", FileMode.Create, FileAccess.Write)) { output.Save(outputFile); } } imageRotationAngle = GetBitmapRotationAngleByRotationFlipType(fType); } } Overlay.Text = info.ToString(); imgStream.Flush(); imgStream.Close(); } else //if (Path.GetExtension(filename).ToLower() == ".jpg") { if (imageRotationAngle == 90) { //rotate other types of image using Image class using (Image imgForRotation = Image.FromStream(imgStream, false, false)) { Overlay.Text = filename + "\n" + imgForRotation.Width + "x" + imgForRotation.Height; imgForRotation.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); imgStream.Seek(0, SeekOrigin.Begin); switch (Path.GetExtension(filename).ToLower()) { case ".png": imgForRotation.Save(imgStream, ImageFormat.Png); break; case ".bmp": imgForRotation.Save(imgStream, ImageFormat.Bmp); break; case ".gif": imgForRotation.Save(imgStream, ImageFormat.Gif); break; } } imgStream.Flush(); imgStream.Close(); imageRotationAngle = 0; // because we already have rotated image } else { Overlay.Text = ""; // we will set it bellow } } } } catch { Overlay.Text = ""; } try { using ( var imgStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read)) { var img = new BitmapImage(); img.BeginInit(); img.CacheOption = BitmapCacheOption.OnLoad; img.StreamSource = imgStream; // load image from stream instead of file img.EndInit(); // Rotate Image if necessary TransformedBitmap transformBmp = new TransformedBitmap(); transformBmp.BeginInit(); transformBmp.Source = img; RotateTransform transform = new RotateTransform(imageRotationAngle); transformBmp.Transform = transform; transformBmp.EndInit(); FullScreenImage.Source = transformBmp; // Initialize rotation variable for next image imageRotationAngle = 0; imageTimer.Start(); //if we failed to get exif data set some basic info if (String.IsNullOrWhiteSpace(Overlay.Text)) { Overlay.Text = filename + "\n" + img.Width + "x" + img.Height; } } } catch { FullScreenImage.Source = null; ShowError("Can not load " + filename + " ! Screensaver paused, press P to unpause."); } }
public static T[,] Transform <T>(this T[,] array, RotateFlipType transformation) { return(Transform <T>(array, FlipRotate2D.FromRotateFlipType(transformation))); }
/// <summary><return> /// <para>true for /// <para>RotateNoneFlipX,</para> /// <para>Rotate180FlipY,</para> /// <para>RotateNoneFlipY,</para> /// <para>Rotate180FlipX;</para> /// </para> /// <para>false for /// <para>RotateNoneFlipNone,</para> /// <para>Rotate180FlipXY,</para> /// <para>RotateNoneFlipXY,</para> /// <para>Rotate180FlipNone,</para> /// <para>Rotate90FlipX,</para> /// <para>Rotate270FlipY,</para> /// <para>Rotate90FlipY,</para> /// <para>Rotate270FlipX,</para> /// <para>Rotate90FlipNone,</para> /// <para>Rotate270FlipXY,</para> /// <para>Rotate270FlipNone,</para> /// <para>Rotate90FlipXY.</para> /// </para> /// </return></summary> public static bool IsAxisReflection(this T _this) { return((_this & T.Rotate90FlipX) == T.RotateNoneFlipX); }
public virtual System.Drawing.Bitmap ResponseGetScreenshot(System.Drawing.RotateFlipType rotateFlip) { return(GlobalsatBitmap.GetBitmap(this.FitnessDevice.ScreenBpp, this.FitnessDevice.ScreenSize, this.FitnessDevice.ScreenRowCol, rotateFlip, this.PacketData)); }
public static T FromRotateFlipType(RotateFlipType value) { int v = (int)value; return(new T((v & 3) * 60 ^ (v >> 2))); }
bool isSkip = true; //接ProcessingDialog 回傳值 略過 private void Button_AutoImport_Click(object sender, RoutedEventArgs e) { Button btnAutoImport = (Button)sender; //先載入原本樣板的圖片 //如果略過就塞回原圖 btnAutoImport.Dispatcher.Invoke(() => { bool isEverChanged = false; btnAutoImport.IsEnabled = false; pd = new ProcessingDialog(); Task t = Task.Factory.StartNew(() => { pd.Dispatcher.Invoke(() => { pd.PText = "圖片偵測中"; pd.PIsIndeterminate = true; pd.ButtonContent = "跳過"; pd.ReturnValueCallback += new ProcessingDialog.ReturnValueDelegate(this.SetReturnValueCallbackFun); pd.Show(); }); //病患資料夾路徑 if (pf == null) { pf = new PatientsFolder(Agencys, Patients, Registration_Date); } //資料表Registrations 處理 if (dbr == null) { dbr = new DBRegistrations(); } //資料表Images 處理 if (dbi == null) { dbi = new DBImages(); } //處理載入BitmapImage if (lbi == null) { lbi = new LoadBitmapImage(); } //載入TemplateImages if (dbti == null) { dbti = new DBTemplateImages(); } tICollection = new ObservableCollection <TemplateImages>(); tICollection = dbti.GetTemplateImagesCollection(Agencys, Patients, TemplateItem, tfvm.TemplateImportDate); //default Image[i] in UserControl Templates int Imagei = 0; int ImageCount = (int)TemplateItem.Template_ImageCount; int DecodePixelWidth = (int)TemplateItem.Template_DecodePixelWidth; while (Imagei < ImageCount) { pd.PText = "圖片 " + (Imagei + 1) + " 偵測中"; //目前處理的Image[i] Image iTarget; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/yes.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/yes.png", DecodePixelWidth); }); //set the paramater default bool isChanged = false; bool detecting = true; while (true) { //開始偵測wifi card路徑 foreach (string f in Directory.GetFiles(Agencys.Agency_WifiCardPath)) { Thread.Sleep(500); string extension = Path.GetExtension(f).ToUpper(); string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff"); if (!Directory.Exists(pf.PatientFullFolderPathOriginal)) { Directory.CreateDirectory(pf.PatientFullFolderPathOriginal); } //System.Drawing.RotateFlipType rft = ImageHelper.RotateImageByExifOrientationData(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension), true); ////複製原圖到目的Original //File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); // Rotate the image according to EXIF data var bmp = new System.Drawing.Bitmap(f); System.Drawing.RotateFlipType fType = ImageHelper.RotateImageByExifOrientationData(bmp, true); if (fType != System.Drawing.RotateFlipType.RotateNoneFlipNone) { bmp.Save(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, GetImageFormat(extension)); } else { File.Copy(f, pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension); } Registration_ID = dbr.CreateRegistrationsAndGetID(Patients, Registration_Date); string imagePath = @"\" + pf.PatientFolderPathOriginal + @"\" + newFileName + @"ori" + extension; string imageFileName = newFileName + @"ori" + extension; string imageSize = "Original"; string imageExtension = extension; //寫資料庫 //INSERT Images int imageID = dbi.InsertImage(imagePath, imageFileName, imageSize, imageExtension, Registration_ID); isEverChanged = true; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); //INSERT TemplateImages dbti.InsertOrUpdateImage(Patients, TemplateItem, tfvm.TemplateImportDate, imageID, imagePath, iTarget.Uid); iTarget.Source = lbi.SettingBitmapImage(pf.PatientFullFolderPathOriginal + @"\" + newFileName + @"ori" + extension, DecodePixelWidth); isChanged = true; }); File.Delete(f); detecting = false; } //ProcessingDialog STOP if (isStop) { isStop = false; TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); var findOriImage = from tc in tICollection where tc.TemplateImage_Number == Imagei.ToString() select tc; if (findOriImage.Count() > 0) { iTarget.Source = lbi.SettingBitmapImage(findOriImage.First().Image_Path, DecodePixelWidth); } else { iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/key.ico", DecodePixelWidth); } }); return; } else { // import pic OR skip import (NEXT) if (!detecting || !isSkip) { if (!isChanged) { TemplateContent.Dispatcher.Invoke(() => { iTarget = new Image(); iTarget = (Image)TemplateContent.FindName("Image" + Imagei); var findOriImage = from tc in tICollection where tc.TemplateImage_Number == Imagei.ToString() select tc; if (findOriImage.Count() > 0) { iTarget.Source = lbi.SettingBitmapImage(findOriImage.First().Image_Path, DecodePixelWidth); } else { iTarget.Source = new BitmapImage(new Uri(@"/DigiDental;component/Resource/no.png", UriKind.RelativeOrAbsolute)); //iTarget.Source = lbi.SettingBitmapImage(@"/DigiDental;component/Resource/key.ico", DecodePixelWidth); } }); } Imagei++; isSkip = true; break; } } } } }).ContinueWith(cw => { //結束 pd.PText = "處理完畢"; pd.Close(); //委派回傳MainWindow //刷新Registrations 資料 //刷新Images 資料 if (isEverChanged) { ReturnValueCallback(Registration_ID, Registration_Date); } GC.Collect(); btnAutoImport.IsEnabled = true; }, TaskScheduler.FromCurrentSynchronizationContext()); }); }
public static string GetJPEGBase64StringFromBitmapImage(BitmapImage bmpImage, long jpegEncoderQuality, System.Drawing.RotateFlipType rotateFlip) { System.Drawing.Bitmap bmp = null; MemoryStream ms = new MemoryStream(); try { System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1); System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; encoderParameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(myEncoder, jpegEncoderQuality); System.Drawing.Imaging.ImageCodecInfo jgpEncoder = GetEncoder(System.Drawing.Imaging.ImageFormat.Jpeg); bmp = UIHelper.BitmapImage2Bitmap(bmpImage); bmp.RotateFlip(rotateFlip); bmp.Save(ms, jgpEncoder, encoderParameters); return(Convert.ToBase64String(ms.ToArray())); } finally { DeleteObject(bmp.GetHbitmap()); bmp.Dispose(); bmp = null; } }
public static T Subtract(this T _this, T other) { byte t = (byte)_this, o = (byte)other; return((T)((((t ^ o) >> 2 ^ t ^ 1) & o & 1) << 1 ^ t ^ o)); }
/// <summary><return> /// <para>true for /// <para>Rotate90FlipX,</para> /// <para>Rotate270FlipY,</para> /// <para>Rotate90FlipY,</para> /// <para>Rotate270FlipX,</para> /// <para>Rotate90FlipNone,</para> /// <para>Rotate270FlipXY,</para> /// <para>Rotate270FlipNone,</para> /// <para>Rotate90FlipXY;</para> /// </para> /// <para>false for /// <para>RotateNoneFlipNone,</para> /// <para>Rotate180FlipXY,</para> /// <para>RotateNoneFlipXY,</para> /// <para>Rotate180FlipNone,</para> /// <para>RotateNoneFlipX,</para> /// <para>Rotate180FlipY,</para> /// <para>RotateNoneFlipY,</para> /// <para>Rotate180FlipX.</para> /// </para> /// </return></summary> public static bool IsSwapDimensions(this T _this) { return((_this & T.Rotate90FlipNone) == T.Rotate90FlipNone); }
/// <summary> /// Rotate or / and Flip the bitmap source to a new source /// </summary> /// <param name="source"></param> /// <param name="type">RoateFlipType</param> /// <returns></returns> public static BitmapSource RotateFlip(this BitmapSource source, System.Drawing.RotateFlipType type) { System.Drawing.Image img = source.ToBitmap(); img.RotateFlip(type); return(img.ToBitmapSource()); }