private static Bitmap DrawCompleteImageToBitmap(IPresentationImage image, float scale, float dpi) { ImageSpatialTransform transform = (ImageSpatialTransform)((ISpatialTransformProvider)image).SpatialTransform; object restoreMemento = transform.CreateMemento(); try { ImageGraphic imageGraphic = ((IImageGraphicProvider)image).ImageGraphic; Rectangle imageRectangle = new Rectangle(0, 0, imageGraphic.Columns, imageGraphic.Rows); transform.Initialize(); transform.ScaleToFit = false; transform.Scale = scale; RectangleF displayRectangle = imageGraphic.SpatialTransform.ConvertToDestination(imageRectangle); int width = (int)Math.Round(displayRectangle.Width); int height = (int)Math.Round(displayRectangle.Height); transform.ScaleToFit = true; return(ImageDrawToBitmap(image, width, height, dpi)); } finally { transform.SetMemento(restoreMemento); } }
public static Bitmap CreatePresentationImageIcon(IPresentationImage image, double tileRatio) { ISpatialTransformProvider provider = image as ISpatialTransformProvider; if (provider == null) { throw new Exception(SR.ConvertTransformProviderFailed); } ImageSpatialTransform spatialTransform = provider.SpatialTransform as ImageSpatialTransform; object memento = spatialTransform.CreateMemento(); Size size = CalculateSize(image.ClientRectangle.Size, tileRatio); Bitmap bitmap = new Bitmap(image.DrawToBitmap(size.Width, size.Height), _iconWidth, Convert.ToInt32((float)(_iconWidth * Convert.ToSingle(tileRatio)))); spatialTransform.SetMemento(memento); return(bitmap); }
private static Bitmap DrawWysiwygImageToBitmap(IPresentationImage image, Rectangle displayRectangle, float scale, float dpi) { ImageSpatialTransform transform = (ImageSpatialTransform)((ISpatialTransformProvider)image).SpatialTransform; object restoreMemento = transform.CreateMemento(); try { int width = (int)(displayRectangle.Width * scale); int height = (int)(displayRectangle.Height * scale); transform.Scale *= scale; return(ImageDrawToBitmap(image, width, height, dpi)); } finally { transform.SetMemento(restoreMemento); } }
public static Bitmap CreatePresentationImagePrintData(IPresentationImage image, RectangleF destRange, double tileRatio, float scale, bool withAnnotation) { ISpatialTransformProvider provider = image as ISpatialTransformProvider; if (provider == null) { Platform.Log(LogLevel.Error, "RectangleF 转换失败"); throw new Exception("转换失败"); } ImageSpatialTransform spatialTransform = provider.SpatialTransform as ImageSpatialTransform; object memento = spatialTransform.CreateMemento(); float num = scale / spatialTransform.Scale; spatialTransform.MoveTo(destRange, scale); Size destSize = new Size(Convert.ToInt32((float)(destRange.Width * num)), Convert.ToInt32((float)(destRange.Height * num))); Bitmap bitmap = DrawToFilmSizeBitmap(destSize, image, tileRatio, withAnnotation); spatialTransform.SetMemento(memento); return(bitmap); }
public static Bitmap CreatePresentationImageIcon(IPresentationImage image, RectangleF destRange, double tileRatio) { if (destRange == RectangleF.Empty) { return(null); } ISpatialTransformProvider provider = image as ISpatialTransformProvider; if (provider == null) { throw new Exception(SR.ConvertTransformProviderFailed); } ImageSpatialTransform spatialTransform = provider.SpatialTransform as ImageSpatialTransform; object memento = spatialTransform.CreateMemento(); spatialTransform.MoveTo(destRange); Size destSize = new Size(Convert.ToInt32(destRange.Width), Convert.ToInt32(destRange.Height)); Bitmap original = DrawToFilmSizeBitmap(destSize, image, tileRatio, true); Bitmap bitmap2 = new Bitmap(original, _iconWidth, (int)(_iconWidth * tileRatio)); original.Dispose(); spatialTransform.SetMemento(memento); return(bitmap2); }
public static Bitmap CreatePresentationImagePrintData(IPresentationImage image, double tileRatio, bool withAnnotation) { Size size; ISpatialTransformProvider provider = image as ISpatialTransformProvider; if (provider == null) { Platform.Log(LogLevel.Error, " 转换失败"); throw new Exception("转换失败"); } ImageSpatialTransform spatialTransform = provider.SpatialTransform as ImageSpatialTransform; object memento = spatialTransform.CreateMemento(); if (!spatialTransform.ScaleToFit) { //Platform.Log(LogLevel.Error, "!spatialTransform.ScaleToFit"); float num = 1f / spatialTransform.Scale; int width = Convert.ToInt32((float)(image.ClientRectangle.Width * num)); int height = Convert.ToInt32((float)(image.ClientRectangle.Height * num)); //if ((width > spatialTransform.SourceWidth) || (height > spatialTransform.SourceHeight)) //{ // float num4 = ((float)image.ClientRectangle.Width) / ((float)image.ClientRectangle.Height); // float num5 = ((float)spatialTransform.SourceWidth) / ((float)spatialTransform.SourceHeight); // if (num4 > num5) // { // size = new Size(spatialTransform.SourceWidth, Convert.ToInt32((float)(((float)spatialTransform.SourceWidth) / num4))); // spatialTransform.Scale = (spatialTransform.Scale * spatialTransform.SourceWidth) / ((float)image.ClientRectangle.Width); // } // else // { // size = new Size(Convert.ToInt32((float)(spatialTransform.SourceHeight * num4)), spatialTransform.SourceHeight); // spatialTransform.Scale = (spatialTransform.Scale * spatialTransform.SourceHeight) / ((float)image.ClientRectangle.Height); // } //} //else { if (width >= 3000 || height >= 3000) { width = (int)(width * 0.3); height = (int)(height * 0.3); } size = new Size(width, height); spatialTransform.Scale = (spatialTransform.Scale * width) / ((float)image.ClientRectangle.Width); } } else { if (spatialTransform.SourceWidth > 3000 || spatialTransform.SourceHeight > 3000) { size = new Size((int)(spatialTransform.SourceWidth * 0.3), (int)(spatialTransform.SourceHeight * 0.3)); } else { size = new Size(spatialTransform.SourceWidth, spatialTransform.SourceHeight); } } Size size2 = CalculateSize(size, tileRatio); if (!withAnnotation) { HideAnnotation(image); } Bitmap bitmap = image.DrawToBitmap(size2.Width, size2.Height); if (!withAnnotation) { ShowAnnotation(image); } spatialTransform.SetMemento(memento); return(bitmap); }