如何在Crystal Report中插入透明图像 [英] How Do I Insert Transparent Image In Crystal Report
问题描述
大家好,我正在开发一个indigeneShip软件,它将所有申请人数据保存在数据库中,包括他们的图片和他们的LOCAL GOVT主席,DISTRICT HEAD,VILLAGE HEAD&申请人签名。我希望生成所有签名(存储在数据库表中使用列的OLE对象数据类型)在水晶报告上通过indigene-certificate透明。
i将它从数据库调用到报告,但麻烦的是,签名的背景变成黑色而不是透明度。
i尝试更改图像键入,因为它在默认的vb报告(即MIMEType)到PNG,但我不能在水晶报告属性中罚款。
然后我注意到水晶报告不支持png格式的图像,但只支持EMF,WMF等都接受透明背景。
如果我用图像路径调用图像,我工作正常。但是当我调用来自保存为OLE对象的数据库时,背景变为白色。
这里是将图像存储到数据库的代码
' 浏览图片
< span class =code-keyword>尝试
Dim dlgImage As FileDialog = 新 OpenFileDialog()
如果 dlgImage.ShowDialog()= DialogResult。确定然后
imgName = dlgImage.FileName
Dim newimg < span class =code-keyword> As 新位图(imgName)
PbSlogo.SizeMode = PictureBoxSizeMode.StretchImage
PbSlogo.Image = DirectC ast (newimg,Image)
结束 如果
dlgImage = 没什么
Catch ae As System.ArgumentException
imgName =
MessageBox.Show(ae.Message.ToString())
Catch ex As 异常
MessageBox.Show(ex.Message.ToString())
结束 尝试
' 保存按钮代码
尝试
如果 imgName<> 然后
< span class =code-keyword> Dim fs As FileStream
fs = 新 FileStream(imgName,FileMode.Open,FileAccess.Read)
Dim picByte 作为 字节()= 新 字节(fs.Length - 1 ){}
fs.Read(picByte, 0 ,System.Convert.ToInt32(fs.Length))
fs.Close()
Dim CN As 新 OleDbConnection(connString)
CN。打开()
Dim strSQL As String
strSQL = UPDATE配置SET stLogo = @Img WHERE ID = 1
Dim imgParam 作为 新 OleDbParameter()
imgParam.OleDbType = OleDbType.Binary
imgParam.ParameterName = Img
imgParam.Value = picByte
Dim cmd 作为 新 OleDbCommand(strSQL,CN)
cmd.Parameters.Add(imgParam)
cmd.ExecuteNonQuery ()
MessageBox.Show( 徽标已成功保存。)
imgName =
cmd.Dispose()
CN.Close()
CN.Dispose()
结束 如果
Catch ex As 异常
MessageBox.Show(ex.Message)
结束 尝试
i非常感谢您的帮助和建议...
谢谢。
请看我对这个问题的评论;我基本上解释了要做什么。
从任何流加载和图像的最简单的基本方法是使用类System.Drawing.Image
以及为此目的设计的其中一个FromStream
方法:Image.FromStream Method(System.Drawing) 。
如果你想使用EMF文件,具体来说,你可以使用派生类System.Drawing.Imaging.Metafile
:
图元文件类(系统。 Drawing.Imaging) 。
关于你使用OLE对象的想法:关于存储图像的问题被问到并回答了太多时间(也许,再次回答太多次),但问题是:我从来没有面对如此奇怪的想法。 OLE对象仅特定于Windows,我认为不仅严重过时,而且它们不是在非OOP平台API上提供OOP API的最佳尝试。但是您的数据库是多平台的。您需要做的就是逐字节存储文件。文件里面的内容并不重要;如果文件适合您,则从数据库中提取的同一文件将完全相同。请参阅: 搜索 - CodeProject 。
另一种方法是使用一些唯一命名的名称系统仅存储文件名。这将是最好的方法,比如服务器环境,您可以将文件存储在主机文件系统中。
-SA
Hello everyone, i am developing an indigeneShip software that keeps all the applicant data in the database including their picture and the signature of their LOCAL GOVT CHAIRMAN, DISTRICT HEAD, VILLAGE HEAD & APPLICANT SIGNATURE. i want generate all the signatures (that are stored in database table using OLE Object data-type of the column) on the crystal report over the indigene-certificate as transparent.
i archived it in calling it from database to the report but the trouble is that, the background of the signature is turning to black instead of transparency.
i tried changing the image type as it is in the default vb report (i.e. MIMEType) to PNG but i couldn't fine it in the crystal report properties.
then i notice that crystal report doesn't support png format of image but only support EMF, WMF etc which all do accept transparent background.
if i call the image using image path, i works fine. but when i call is from the database that is saved as OLE Object the background is becoming white.
here are the code to store the image to the database
'browse the image
Try
Dim dlgImage As FileDialog = New OpenFileDialog()
If dlgImage.ShowDialog() = DialogResult.OK Then
imgName = dlgImage.FileName
Dim newimg As New Bitmap(imgName)
PbSlogo.SizeMode = PictureBoxSizeMode.StretchImage
PbSlogo.Image = DirectCast(newimg, Image)
End If
dlgImage = Nothing
Catch ae As System.ArgumentException
imgName = " "
MessageBox.Show(ae.Message.ToString())
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
'save button code
Try
If imgName <> "" Then
Dim fs As FileStream
fs = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picByte As Byte() = New Byte(fs.Length - 1) {}
fs.Read(picByte, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim CN As New OleDbConnection(connString)
CN.Open()
Dim strSQL As String
strSQL = "UPDATE configuration SET stLogo = @Img WHERE ID=1"
Dim imgParam As New OleDbParameter()
imgParam.OleDbType = OleDbType.Binary
imgParam.ParameterName = "Img"
imgParam.Value = picByte
Dim cmd As New OleDbCommand(strSQL, CN)
cmd.Parameters.Add(imgParam)
cmd.ExecuteNonQuery()
MessageBox.Show("Logo successfully saved.")
imgName = ""
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
i would appreciate your help and suggestion...
thank you.
Please see my comment to the question; I basically explain what to do.
The simplest basic way of loading and image from any stream is using the classSystem.Drawing.Image
and one of itsFromStream
methods designed for this purpose: Image.FromStream Method (System.Drawing).
If you want to work with EMF files, specifically, you can use derived classSystem.Drawing.Imaging.Metafile
:
Metafile Class (System.Drawing.Imaging).
As to your idea to use OLE object: the question about storing images of was asked and answered too many times (perhaps, too many times to answer it again), but the thing is: I never faced so weird idea. OLE objects are specific only to Windows, and I think not only badly obsolete, but they have been not the best attempt to provide OOP API on the non-OOP platform API. But your database is multiplatform. All you need to do is to store the files byte by byte. It does not matter what's inside the files; if a file works for you, the same file extracted from your database will do exactly the same. Please see: Search — CodeProject.
Another approach is storing only the file names using some unique-naming name system. It would be the best approach, say, a server environment, where you can store the file in the host file system.
—SA
这篇关于如何在Crystal Report中插入透明图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!