- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已尝试搜索此代码,并且代码在我所见的范围内应该可以工作,但是由于某种原因,我的 Crystal Report 中的结果图像是 5 页而不是 1 页!
基本上,我有一个 Crystal 报表,其中包含从 BlobField 获取的整页图像,当源图像为 2409 像素宽和 3436 像素高 @ 300 dpi 时,它可以完美运行。
当我尝试使用 1700 宽 x 2436 高 @ 200 dpi 的源图像时,图像高度太大并且将报告卡在下一页上
我想“没问题,我只需调整图像大小,报告就会正确显示”,但我在这样做时遇到了很大困难。这是我目前正在使用的代码——当使用“正常”图像大小时而这段代码,报告中的一切都显示得很好,但如果我需要调整大小,它会延伸到五页以上,这比不理会它还要糟糕! :(
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length - 1) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
'Byte[] to image
Dim imgMemoryStream = New IO.MemoryStream(Image)
Dim myImage = Drawing.Image.FromStream(imgMemoryStream)
' Check if image is 2409 wide, if it's not then resize to 2409 while preserving aspect ratio. WIN.
If myImage.Width <> 2409 Then
MsgBox("myimage before: " & myImage.Width & " by " & myImage.Height)
myImage = ImageResize(myImage, 3436, 2409)
MsgBox("myimage after: " & myImage.Width & " by " & myImage.Height)
Else
MsgBox("myimage (already correct for printing): " & myImage.Width & " by " & myImage.Height)
End If
Dim imgMemoryStream2 As IO.MemoryStream = New IO.MemoryStream()
myImage.Save(imgMemoryStream2, System.Drawing.Imaging.ImageFormat.Jpeg)
Image = imgMemoryStream2.ToArray
objDataRow(strImageField) = Image
Public Shared Function ImageResize(ByVal image As System.Drawing.Image, _
ByVal height As Int32, ByVal width As Int32) As System.Drawing.Image
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(width, height, image.PixelFormat)
If bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format1bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format4bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format8bppIndexed Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Undefined Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.DontCare Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format16bppArgb1555 Or _
bitmap.PixelFormat = Drawing.Imaging.PixelFormat.Format16bppGrayScale Then
Throw New NotSupportedException("Pixel format of the image is not supported.")
End If
Dim graphicsImage As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bitmap)
graphicsImage.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
graphicsImage.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphicsImage.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height)
graphicsImage.Dispose()
Return bitmap
End Function
最佳答案
您应该已经将图像(作为 byte[])存储在某个地方,将其传递给此 ResizeBytes 函数,以及您希望返回的图像的新尺寸。
private byte[] ResizeBytes(byte[] byteImageIn, int NewWidth, int NewHeight)
{
//Convert Bytes to Image
MemoryStream ms1 = new MemoryStream(byteImageIn);
Image img = Image.FromStream(ms1);
//Convert Image in to new image with new dimensions, padding with a white background
img = FixedSize(img, NewWidth, NewHeight);
//Convert image back to a byte array
MemoryStream ms2 = new MemoryStream();
img.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageBytes = ms2.ToArray();
return imageBytes;
}
private Image FixedSize(Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width -
(sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height -
(sourceHeight * nPercent)) / 2);
}
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(Width, Height,
PixelFormat.Format48bppRgb); //Format24bppRgb
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.Clear(Color.White);
grPhoto.InterpolationMode =
InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
关于arrays - 调整图像大小并放置在 CrystalReports BlobField 的字节数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036677/
我正在尝试在 Crystal Reports 中创建每日日程表,以显示诊所医生的预约。旁边是一天中的时间,从早上 7 点开始到下午 5 点,以半小时为增量。顶部是医生的名字。每列都将医生的预约与时间正
我收到错误“CrystalDecisions.CrystalReports.Engine.dll”丢失。我可以从哪里下载 DLL。我已经安装了 sap CrystalDecisions 但它给出了同样
我已尝试搜索此代码,并且代码在我所见的范围内应该可以工作,但是由于某种原因,我的 Crystal Report 中的结果图像是 5 页而不是 1 页! 基本上,我有一个 Crystal 报表,其中包含
我的用户的终端运行 2 应用程序。其中一个我使用 VS 2005 和 Crystal Reports 捆绑版本构建了一个应用程序,另一个使用不同 Crystal Report 版本的外部产品。大约有
是否可以查询 Crystal CMS 数据库并获取有意义的数据?数据似乎已加密。 我正在运行 Business Objects Crystal Report Server 版本 11.5 最佳答案 实
过去几天我一直在研究这个问题,但我似乎无法弄清楚。 我有一个 c# WinForms 应用程序,它使用 ReportDocument 加载报表并将其放入 Crystal Report Viewer,以
我正在为使用 Crystal Reports API 显示和打印表单的客户部署桌面应用程序。我正在使用 InstallShield 2012 构建安装程序。我还包括了 .NET 4.0 Framewo
一直在工作单应用程序上工作,并且进展顺利。前几天,我下载并安装了Crystal报表,并在我的项目中设计了一个报表。经过编码后,我决定对其进行测试。当我在VS 2010中重建解决方案时,突然出现了66个
我写了一个使用 ReportViewer 的 .NET DLL在 VS2010 中。在开发计算机上,它运行良好。但是,当我在客户端上安装该程序时,我收到错误消息 Crystaldecisions.Cr
在日文Win10系统机器上的一个VB6项目中,这条线在代码运行和调试过程中运行良好。 Private lReport As CRAXDRT.Report ... ... ... Call lRepor
我正在使用 CrystalDecisions.CrystalReports.Engine获取 FormulaField、FieldObject 等的属性。但是如何获取 FieldObject 的抑制条
我们有一个用 .NET 4.0 编写的应用程序,它使用这个 SAP Crystal Reports。虽然相同的构建 (x86) 在安装了 .NET 4.0 框架 (x86) 和 CrystalRepo
我正在开发一个 Asp.Net 3.5 应用程序,我需要打印一些应用程序生成的报告。 我以前使用过 SSRS,但我在设计功能方面遇到了很多问题。因此,我们现在正在寻找 Crystal Reports
我正在使用数据集文件的 TableAdapter 方法从数据库中获取数据,和 Crysral 报表对象来创建报表而不是 CrystalReport 文件本身。(基本上我不想使用Physical Cry
我遇到了一个很奇怪的问题看起来很有趣看起来有些东西和我在一起很有趣。我正在使用 Crystal-Report 版本 13.0.2000.0 和 Visual Studio 2010。几天前,我收到了与
我是一名优秀的程序员,十分优秀!