public void drawImageScale( javax.microedition.lcdui.Image img, float x, float y, System.Drawing.RotateFlipType transform, float scale) { if (img.killed) { return; } if (scale == 1) { _drawImage(img.dimg, x, y, img.getWidth(), img.getHeight(), 0, 0, img.getWidth(), img.getHeight(), transform); } else { _drawImage(img.dimg, x, y, img.getWidth() * scale, img.getHeight() * scale, 0, 0, img.getWidth(), img.getHeight(), transform); } }
/// <summary> /// Rotates the bitmap to the correct orientation if the given bitmap has the correct geometry for a Fax, with the correct resolution, and the correct size. /// </summary> public static void RotateBitmapIfFaxMatch(Bitmap bmp, System.Drawing.RotateFlipType type = RotateFlipType.Rotate90FlipNone) { if ( (bmp.HorizontalResolution == ImageUtility.FAX_TIF_HOR_RES) && (bmp.Width == ImageUtility.FAX_TIF_HOR_PX) && (bmp.VerticalResolution == ImageUtility.FAX_TIF_VER_RES_HI || bmp.VerticalResolution == ImageUtility.FAX_TIF_VER_RES_LOW) && (bmp.Height == ImageUtility.FAX_TIF_VER_PX_LGL_HI || bmp.Height == ImageUtility.FAX_TIF_VER_PX_LGL_LOW || bmp.Height == ImageUtility.FAX_TIF_VER_PX_LTR_HI || bmp.Height == ImageUtility.FAX_TIF_VER_PX_LTR_LOW) ) //This is a standard fax. No need to rotate. { return; } if ( (bmp.VerticalResolution == ImageUtility.FAX_TIF_HOR_RES) && (bmp.Height == ImageUtility.FAX_TIF_HOR_PX) && (bmp.HorizontalResolution == ImageUtility.FAX_TIF_VER_RES_HI || bmp.HorizontalResolution == ImageUtility.FAX_TIF_VER_RES_LOW) && (bmp.Width == ImageUtility.FAX_TIF_VER_PX_LGL_HI || bmp.Width == ImageUtility.FAX_TIF_VER_PX_LGL_LOW || bmp.Width == ImageUtility.FAX_TIF_VER_PX_LTR_HI || bmp.Width == ImageUtility.FAX_TIF_VER_PX_LTR_LOW) )//This is a standard fax on its side. Rotate it. { bmp.RotateFlip(type); return; } throw new Exception("Tiff does not conform to a Fax size."); }
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(); } } }
public void drawImageRegion( javax.microedition.lcdui.Image img, float x, float y, float sx, float sy, float sw, float sh, System.Drawing.RotateFlipType transform) { if (img.killed) { return; } _drawImage(img.dimg, x, y, sw, sh, sx, sy, sw, sh, transform); }
public virtual Bitmap GetScreenshot(IJobMonitor jobMonitor) { Bitmap result = null; //Note: No check for connected here if (this.Open()) { try { GlobalsatPacket packet = PacketFactory.GetScreenshot(); GlobalsatPacket response = (GlobalsatPacket)this.SendPacket(packet); System.Drawing.RotateFlipType rotate = RotateFlipType.RotateNoneFlipNone; if (this.FitnessDevice.CanRotateScreen) { //try getting screen orientaion try { packet = PacketFactory.GetSystemConfiguration2(); GlobalsatPacket response2 = (GlobalsatPacket)this.SendPacket(packet); GlobalsatSystemConfiguration2 systemInfo = response2.ResponseGetSystemConfiguration2(); if (systemInfo.ScreenOrientation == 1) { rotate = RotateFlipType.Rotate90FlipNone; } } catch {} } result = response.ResponseGetScreenshot(rotate); } catch (Exception e) { jobMonitor.ErrorText = Properties.Resources.Device_GetInfo_Error + e; //throw new Exception(Properties.Resources.Device_GetInfo_Error + e); } finally { this.Close(); } } if (!this.DataRecieved) { NoCommunicationError(jobMonitor); } return(result); }
public void Rotate(System.Drawing.RotateFlipType rotate) { try { System.Drawing.Bitmap B = this.Bitmap.ToBitmap(); B.RotateFlip(rotate); using (MemoryStream memoryStream = new MemoryStream()) { B.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); B.Dispose(); memoryStream.Seek(0, SeekOrigin.Begin); byte[] data = new byte[memoryStream.Length]; memoryStream.Read(data, 0, (int)memoryStream.Length); _bitmap = new ByteArrayBitmap(data); } } catch (Exception ee) { DebugMessageLogger.LogError(ee); } }
public static void RotateImageFile(string filepath, System.Drawing.RotateFlipType rft) { Image img = null; using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read)) { try { img = Image.FromStream(stream); } catch { } finally { stream.Close(); } } if (img != null) { try { img.RotateFlip(rft); img.Save(filepath); } catch { } finally { img.Dispose(); } } }
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); } }
public static bool GenerateBarcode( int barcodeEncoding , int width , int height , BarcodeLib.AlignmentPositions alignmentPosition , System.Drawing.RotateFlipType rotateFlipType , BarcodeLib.LabelPositions labelPosition , string stringToEncode , string imagePathAndName , BarcodeLib.SaveTypes saveType , System.Windows.Forms.GroupBox barcode , ref string errorMessage ) { errorMessage = string.Empty; BarcodeLib.Barcode b = new BarcodeLib.Barcode(); b.Alignment = alignmentPosition; BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED; if (barcodeEncoding > 1) { barcodeEncoding = 1; } switch (barcodeEncoding) { ////case 0: type = BarcodeLib.TYPE.UPCA; break; //"UPC-A" ////case 1: type = BarcodeLib.TYPE.UPCE; break; //"UPC-E" ////case 2: type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT; break; //"UPC 2 Digit Ext." ////case 3: type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT; break; //"UPC 5 Digit Ext". ////case 4: type = BarcodeLib.TYPE.EAN13; break; //"EAN-13" ////case 5: type = BarcodeLib.TYPE.JAN13; break; //"JAN-13" ////case 6: type = BarcodeLib.TYPE.EAN8; break; //"EAN-8" ////case 7: type = BarcodeLib.TYPE.ITF14; break; //"ITF-14" //case 0: type = BarcodeLib.TYPE.Interleaved2of5; break; //"Interleaved 2 of 5" //case 1: type = BarcodeLib.TYPE.Standard2of5; break; //"Standard 2 of 5" ////case 10: type = BarcodeLib.TYPE.Codabar; break; //"Codabar" ////case 11: type = BarcodeLib.TYPE.PostNet; break; //"PostNet" //case 2: type = BarcodeLib.TYPE.BOOKLAND; break; //"Bookland/ISBN" //case 3: type = BarcodeLib.TYPE.CODE11; break; //"Code 11" case 0: type = BarcodeLib.TYPE.CODE39; break; //"Code 39" //case 5: type = BarcodeLib.TYPE.CODE39Extended; break; //"Code 39 Extended" //case 6: type = BarcodeLib.TYPE.CODE39_Mod43; break; //"Code 39 Mod 43" //case 7: type = BarcodeLib.TYPE.CODE93; break; //"Code 93" case 1: type = BarcodeLib.TYPE.CODE128; break; //"Code 128" //case 9: type = BarcodeLib.TYPE.CODE128A; break; //"Code 128-A" //case 10: type = BarcodeLib.TYPE.CODE128B; break; //"Code 128-B" //case 11: type = BarcodeLib.TYPE.CODE128C; break; //"Code 128-C" //case 12: type = BarcodeLib.TYPE.LOGMARS; break; //"LOGMARS" //case 13: type = BarcodeLib.TYPE.MSI_Mod10; break; //"MSI" //case 14: type = BarcodeLib.TYPE.TELEPEN; break; //"Telepen" ////case 25: type = BarcodeLib.TYPE.FIM; break; //"FIM" ////case 26: type = BarcodeLib.TYPE.PHARMACODE; break; //"Pharmacode" default: type = BarcodeLib.TYPE.CODE128; break; //"Code 128" }//switch try { if (type != BarcodeLib.TYPE.UNSPECIFIED) { b.IncludeLabel = true; b.RotateFlipType = rotateFlipType; b.LabelPosition = labelPosition; if (barcode == null) { barcode = new System.Windows.Forms.GroupBox(); // // barcode // barcode.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; barcode.Dock = System.Windows.Forms.DockStyle.Fill; barcode.Location = new System.Drawing.Point(0, 0); barcode.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); barcode.Name = "barcode"; barcode.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); barcode.Size = new System.Drawing.Size(754, 414); barcode.TabIndex = 36; barcode.TabStop = false; barcode.Text = "Barcode Image"; barcode.Visible = false; } //===== Encoding performed here ===== barcode.BackgroundImage = b.Encode(type, stringToEncode, System.Drawing.Color.Black, System.Drawing.Color.White, width, height); //=================================== //reposition the barcode image to the middle barcode.Location = new System.Drawing.Point((barcode.Location.X + barcode.Width / 2) - barcode.Width / 2, (barcode.Location.Y + barcode.Height / 2) - barcode.Height / 2); if (!string.IsNullOrEmpty(imagePathAndName)) { b.SaveImage(imagePathAndName, saveType); } } //if } //try catch (Exception ex) { errorMessage = ex.Message; return(false); }//catch return(true); }
//------------------------------------------------------------------------------------------------------------------ private void _drawImage(System.Drawing.Image dimg, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh, System.Drawing.RotateFlipType transform) { // Create parallelogram for drawing original image. PointF ulCorner1 = new PointF(0, 0); PointF urCorner1 = new PointF(dw, 0); PointF llCorner1 = new PointF(0, dh); PointF[] destPara1 = { ulCorner1, urCorner1, llCorner1 }; // Create rectangle for source image. RectangleF srcRect = new RectangleF(sx, sy, sw, sh); System.Drawing.Drawing2D.Matrix mtx = dg.Transform; try { dg.TranslateTransform(dx, dy); switch (transform) { case System.Drawing.RotateFlipType.RotateNoneFlipX: //4 dg.TranslateTransform(sw, 0); dg.ScaleTransform(-1, 1); break; case System.Drawing.RotateFlipType.RotateNoneFlipY: //6 dg.TranslateTransform(0, sh); dg.ScaleTransform(1, -1); break; //case TRANS_180: case System.Drawing.RotateFlipType.RotateNoneFlipXY: //2 dg.TranslateTransform(sw, sh); dg.ScaleTransform(-1, -1); break; case System.Drawing.RotateFlipType.Rotate90FlipNone: //1 dg.TranslateTransform(sh, 0); dg.RotateTransform(90); break; case System.Drawing.RotateFlipType.Rotate270FlipNone: //3 dg.TranslateTransform(0, sw); dg.RotateTransform(270); break; case System.Drawing.RotateFlipType.Rotate90FlipX: //5 dg.TranslateTransform(sh, 0); dg.RotateTransform(90); dg.TranslateTransform(sw, 0); dg.ScaleTransform(-1, 1); break; case System.Drawing.RotateFlipType.Rotate270FlipX: //7 dg.TranslateTransform(0, sw); dg.RotateTransform(270); dg.TranslateTransform(sw, 0); dg.ScaleTransform(-1, 1); break; } //try //{ dg.DrawImage(dimg, destPara1, srcRect, System.Drawing.GraphicsUnit.Pixel, imgAttr); //} //catch (Exception err) //{ // Console.WriteLine(err.Message); // Console.WriteLine(err.StackTrace); //} } finally { dg.Transform = mtx; } }