使用FreeImage库.... [英] Using the FreeImage Library ....

查看:93
本文介绍了使用FreeImage库....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我想将system.drawing.image或位图转换为FreeImage

位图。我正在使用下面的代码。注意:我遇到的问题并不是
似乎与FreeImage库本身有关而不是Windows API

调用。我到底做错了什么?这是我在下面使用的代码,但结果是黑色图像而不是我放的图像

in。有什么想法吗?非常感谢您的时间!

此致,

Christopher Koeber


PS:FreeImage类是freeimage的一部分项目。您可以访问
http://freeimage.sourceforge.net 了解更多信息。


受保护的MainImage作为新的FreeImage

私有声明函数GetDIBits Lib" gdi32.dll" (ByVal aHDC As Int32,

ByVal hBitmap As IntPtr,ByVal nStartScan As Int32,ByVal nNumScans As

Int32,ByVal lpBits As IntPtr,ByRef lpBI As BITMAPINFO,ByVal wUsage As

Int32)作为Int32

私有声明函数GetObject Lib" gdi32.dll"别名GetObjectA (ByVal

hObject As IntPtr,ByVal nCount As Int32,ByRef lpObject as GDIBITMAP)As

Int32

私有声明函数GetDC Lib" user32的.dll" (ByVal hwnd As IntPtr)As

Int32

Private Const DIB_RGB_COLORS As Integer = 0

Private DevContext As Integer


< StructLayout(LayoutKind.Sequential)> _

私有结构GDIBITMAP

公共bmType为Int32

公共bmWidth为Int32

公共bmHeight为Int32

Public bmWidthBytes As Int32

Public bmPlanes As Int16

结束结构


公共函数ConvertHBITMAPToFreeImage(ByVal WindowHandle作为IntPtr,

ByVal ImageToConvert作为位图)作为Int32

尝试

Dim SrcBitmap作为GDIBITMAP

Dim成功作为Int32

Dim ImgHeight作为整数

Dim ImgBits作为IntPtr

Dim ImgInfo作为BITMAPINFO

Dim HBITMAP作为IntPtr = ImageToConvert.GetHbitmap(Color.White)

GetObject(HBITMAP,Marshal.SizeOf(SrcBitmap) ,SrcBitmap)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''然而,我尝试了同样的结果,黑色图像

....

DevContext = GetDC(WindowHandle)

''' '''

ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,

ImageToConvert.Height,SrcBitmap.bmBitsPixel)

ImgHeight = MainImage.GetHeight (ConvertHBITMAPToFreeImage)

ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)

ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)

''''''' '这条线总是为我返回零,给出了什么?

成功= GetDIBits(DevContext,HBITMAP,0,ImgHeight,ImgBits,ImgInfo,

DIB_RGB_COLORS)

''''''

如果成功= 0则抛出新例外(从常规图像转换为
到FREEIMAGE失败。 ..!")

Catch ex As Exception

MsgBox(ex.Message,MsgBoxStyle.Critical,与FreeImage转换错误

代码!与现状t;)

结束尝试

结束功能

Dear all,
I would like to convert a system.drawing.image or bitmap to a FreeImage
bitmap. I am using the code below. NOTE: the problem I am having doesn''t
seem to be with the FreeImage Library itself bit rather with the Windows API
calls. Am I doing something wrong on that end? This is the code that I am
using below, but the result is a black image and not the image that I put
in. Any ideas? Thank you very much for your time!
Sincerely,
Christopher Koeber

PS: The FreeImage Class is part of the freeimage project. You can visit
http://freeimage.sourceforge.net for more info.

Protected MainImage As New FreeImage
Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr, ByVal nStartScan As Int32, ByVal nNumScans As
Int32, ByVal lpBits As IntPtr, ByRef lpBI As BITMAPINFO, ByVal wUsage As
Int32) As Int32
Private Declare Function GetObject Lib "gdi32.dll" Alias "GetObjectA" (ByVal
hObject As IntPtr, ByVal nCount As Int32, ByRef lpObject As GDIBITMAP) As
Int32
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As
Int32
Private Const DIB_RGB_COLORS As Integer = 0
Private DevContext As Integer

<StructLayout(LayoutKind.Sequential)> _
Private Structure GDIBITMAP
Public bmType As Int32
Public bmWidth As Int32
Public bmHeight As Int32
Public bmWidthBytes As Int32
Public bmPlanes As Int16
Public bmBitsPixel As Int16
Public bmBits As Int32
End Structure

Public Function ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap) As Int32
Try
Dim SrcBitmap As GDIBITMAP
Dim Success As Int32
Dim ImgHeight As Integer
Dim ImgBits As IntPtr
Dim ImgInfo As BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP, Marshal.SizeOf(SrcBitmap), SrcBitmap)
'''''' On the freeimage sources, I wat told to put Null, or nothing in VB.NET,
for this to work. I tried that, however, with the same result, black image
....
DevContext = GetDC(WindowHandle)
''''''
ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height, SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)
'''''''' This line always returns zero for me, what gives?
Success = GetDIBits(DevContext, HBITMAP, 0, ImgHeight, ImgBits, ImgInfo,
DIB_RGB_COLORS)
''''''''
If Success = 0 Then Throw New Exception("The conversion from a regular image
to a FREEIMAGE failed ...!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error with FreeImage Conversion
code!")
End Try
End Function

推荐答案

Chris Chris,
http://www.members.lycos.co。 uk / nickpatemanpwp /

点击我自己的软件

点击FreeScript in VB.NET (您需要向下滚动到VB.NET

部分


然后您将能够下载将FreeImage转换为
的示例
a .NET Bitmap,我相信它可以很容易地适应反向工作。

但是说,使用Bitmaps *如果你拥有<可能会有点棘手br />
自己提供所有数据和标题信息。


尼克。


" Christopher Kurtis Koeber" < c _ ****** @ myrealbox.com>在留言中写道

news:%2 **************** @ TK2MSFTNGP15.phx。 gbl ...
Hi Chris,

http://www.members.lycos.co.uk/nickpatemanpwp/

Click "My Own Software"
Click "FreeImage In VB.NET" (You will need to scroll down to the VB.NET
Section

You will then be able to download an example of converting FreeImage to
a .NET Bitmap, I''m sure it can be easily adapted to work in the reverse.
But saying that, working with Bitmaps *can* be a bit tricky if your having
to supply all of the data and header information yourself.

Nick.

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
亲爱的,
我想将system.drawing.image或位图转换为FreeImage
位图。我正在使用下面的代码。我遇到的问题似乎与FreeImage库本身有关,而不是Windows
API调用。我在这方面做错了吗?这是我的代码我在下面使用,但结果是黑色的ima ge而不是我放入的图像。有什么想法吗?非常感谢您的时间!
此致,Christopher Koeber

PS:FreeImage类是freeimage项目的一部分。您可以访问
http://freeimage.sourceforge.net 了解更多信息。

受保护的MainImage作为新的FreeImage
私有声明函数GetDIBits Lib" gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr,ByVal nStartScan As Int32,ByVal nNumScans As
Int32,ByVal lpBits As IntPtr,ByRef lpBI As BITMAPINFO,ByVal wUsage As
Int32)As Int32
私有声明函数GetObject Lib" gdi32.dll"别名GetObjectA
(ByVal hObject As IntPtr,ByVal nCount As Int32,ByRef lpObject As
GDIBITMAP)As Int32
Private Declare Function GetDC Lib" user32.dll" (ByVal hwnd As IntPtr)As
Int32
私有Const DIB_RGB_COLORS As Integer = 0
私有DevContext为整数

< StructLayout(LayoutKind.Sequential)> _
私有结构GDIBITMAP
公共bmType为Int32
公共bmWidth为Int32
公共bmHeight为Int32
公共bmWidthBytes为Int32
公共bmPlanes为Int16
Public bmBitsPixel As Int16
Public bmBits As Int32


公共函数ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap)As Int32
尝试
Dim SrcBitmap作为GDIBITMAP
Dim成功作为Int32
Dim ImgHeight作为整数
Dim ImgBits作为IntPtr
Dim ImgInfo作为BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP,Marshal.SizeOf(SrcBitmap),SrcBitmap)

''''''在freeimage来源,我告诉你在VB.NET中放入Null,或者什么都不用,这样才能工作。然而,我尝试了同样的结果,
黑色图像......
DevContext = GetDC(WindowHandle)
''''''

ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height,SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)

''''''''这行总是为我返回零,是什么给出的?
成功= GetDIBits(DevContext,HBITMAP,0,ImgHeight,ImgBits ,ImgInfo,
DIB_RGB_COLORS)
''''''''

如果成功= 0则抛出新例外(从常规
图像转换)到FREEIMAGE失败了......!>
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Critical,FreeImage Conversion错误代码!)结束尝试
结束功能
Dear all,
I would like to convert a system.drawing.image or bitmap to a FreeImage
bitmap. I am using the code below. NOTE: the problem I am having doesn''t
seem to be with the FreeImage Library itself bit rather with the Windows
API calls. Am I doing something wrong on that end? This is the code that I
am using below, but the result is a black image and not the image that I
put in. Any ideas? Thank you very much for your time!
Sincerely,
Christopher Koeber

PS: The FreeImage Class is part of the freeimage project. You can visit
http://freeimage.sourceforge.net for more info.

Protected MainImage As New FreeImage
Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr, ByVal nStartScan As Int32, ByVal nNumScans As
Int32, ByVal lpBits As IntPtr, ByRef lpBI As BITMAPINFO, ByVal wUsage As
Int32) As Int32
Private Declare Function GetObject Lib "gdi32.dll" Alias "GetObjectA"
(ByVal hObject As IntPtr, ByVal nCount As Int32, ByRef lpObject As
GDIBITMAP) As Int32
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As
Int32
Private Const DIB_RGB_COLORS As Integer = 0
Private DevContext As Integer

<StructLayout(LayoutKind.Sequential)> _
Private Structure GDIBITMAP
Public bmType As Int32
Public bmWidth As Int32
Public bmHeight As Int32
Public bmWidthBytes As Int32
Public bmPlanes As Int16
Public bmBitsPixel As Int16
Public bmBits As Int32
End Structure

Public Function ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap) As Int32
Try
Dim SrcBitmap As GDIBITMAP
Dim Success As Int32
Dim ImgHeight As Integer
Dim ImgBits As IntPtr
Dim ImgInfo As BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP, Marshal.SizeOf(SrcBitmap), SrcBitmap)
'''''' On the freeimage sources, I wat told to put Null, or nothing in
VB.NET, for this to work. I tried that, however, with the same result,
black image ...
DevContext = GetDC(WindowHandle)
''''''
ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height, SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)
'''''''' This line always returns zero for me, what gives?
Success = GetDIBits(DevContext, HBITMAP, 0, ImgHeight, ImgBits, ImgInfo,
DIB_RGB_COLORS)
''''''''
If Success = 0 Then Throw New Exception("The conversion from a regular
image to a FREEIMAGE failed ...!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error with FreeImage Conversion
code!")
End Try
End Function



你好Chris,

http://www.members.lycos.co.uk/nickpatemanpwp/


点击我自己的软件

点击 ; FreeScript中的VB.NET (您需要向下滚动到VB.NET

部分


然后您将能够下载将FreeImage转换为
的示例
a .NET Bitmap,我相信它可以很容易地适应反向工作。

但是说,使用Bitmaps *如果你拥有<可能会有点棘手br />
自己提供所有数据和标题信息。


尼克。


" Christopher Kurtis Koeber" < c _ ****** @ myrealbox.com>在留言中写道

news:%2 **************** @ TK2MSFTNGP15.phx。 gbl ...
Hi Chris,

http://www.members.lycos.co.uk/nickpatemanpwp/

Click "My Own Software"
Click "FreeImage In VB.NET" (You will need to scroll down to the VB.NET
Section

You will then be able to download an example of converting FreeImage to
a .NET Bitmap, I''m sure it can be easily adapted to work in the reverse.
But saying that, working with Bitmaps *can* be a bit tricky if your having
to supply all of the data and header information yourself.

Nick.

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
亲爱的,
我想将system.drawing.image或位图转换为FreeImage
位图。我正在使用下面的代码。我遇到的问题似乎与FreeImage库本身有关,而不是Windows
API调用。我在这方面做错了吗?这是我的代码我在下面使用,但结果是黑色的ima ge而不是我放入的图像。有什么想法吗?非常感谢您的时间!
此致,Christopher Koeber

PS:FreeImage类是freeimage项目的一部分。您可以访问
http://freeimage.sourceforge.net 了解更多信息。

受保护的MainImage作为新的FreeImage
私有声明函数GetDIBits Lib" gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr,ByVal nStartScan As Int32,ByVal nNumScans As
Int32,ByVal lpBits As IntPtr,ByRef lpBI As BITMAPINFO,ByVal wUsage As
Int32)As Int32
私有声明函数GetObject Lib" gdi32.dll"别名GetObjectA
(ByVal hObject As IntPtr,ByVal nCount As Int32,ByRef lpObject As
GDIBITMAP)As Int32
Private Declare Function GetDC Lib" user32.dll" (ByVal hwnd As IntPtr)As
Int32
私有Const DIB_RGB_COLORS As Integer = 0
私有DevContext为整数

< StructLayout(LayoutKind.Sequential)> _
私有结构GDIBITMAP
公共bmType为Int32
公共bmWidth为Int32
公共bmHeight为Int32
公共bmWidthBytes为Int32
公共bmPlanes为Int16
Public bmBitsPixel As Int16
Public bmBits As Int32


公共函数ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap)As Int32
尝试
Dim SrcBitmap作为GDIBITMAP
Dim成功作为Int32
Dim ImgHeight作为整数
Dim ImgBits作为IntPtr
Dim ImgInfo作为BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP,Marshal.SizeOf(SrcBitmap),SrcBitmap)

''''''在freeimage来源,我告诉你在VB.NET中放入Null,或者什么都不用,这样才能工作。然而,我尝试了同样的结果,
黑色图像......
DevContext = GetDC(WindowHandle)
''''''

ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height,SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)

''''''''这行总是为我返回零,是什么给出的?
成功= GetDIBits(DevContext,HBITMAP,0,ImgHeight,ImgBits ,ImgInfo,
DIB_RGB_COLORS)
''''''''

如果成功= 0则抛出新例外(从常规
图像转换)到FREEIMAGE失败了......!>
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Critical,FreeImage Conversion错误代码!)结束尝试
结束功能
Dear all,
I would like to convert a system.drawing.image or bitmap to a FreeImage
bitmap. I am using the code below. NOTE: the problem I am having doesn''t
seem to be with the FreeImage Library itself bit rather with the Windows
API calls. Am I doing something wrong on that end? This is the code that I
am using below, but the result is a black image and not the image that I
put in. Any ideas? Thank you very much for your time!
Sincerely,
Christopher Koeber

PS: The FreeImage Class is part of the freeimage project. You can visit
http://freeimage.sourceforge.net for more info.

Protected MainImage As New FreeImage
Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr, ByVal nStartScan As Int32, ByVal nNumScans As
Int32, ByVal lpBits As IntPtr, ByRef lpBI As BITMAPINFO, ByVal wUsage As
Int32) As Int32
Private Declare Function GetObject Lib "gdi32.dll" Alias "GetObjectA"
(ByVal hObject As IntPtr, ByVal nCount As Int32, ByRef lpObject As
GDIBITMAP) As Int32
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As
Int32
Private Const DIB_RGB_COLORS As Integer = 0
Private DevContext As Integer

<StructLayout(LayoutKind.Sequential)> _
Private Structure GDIBITMAP
Public bmType As Int32
Public bmWidth As Int32
Public bmHeight As Int32
Public bmWidthBytes As Int32
Public bmPlanes As Int16
Public bmBitsPixel As Int16
Public bmBits As Int32
End Structure

Public Function ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap) As Int32
Try
Dim SrcBitmap As GDIBITMAP
Dim Success As Int32
Dim ImgHeight As Integer
Dim ImgBits As IntPtr
Dim ImgInfo As BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP, Marshal.SizeOf(SrcBitmap), SrcBitmap)
'''''' On the freeimage sources, I wat told to put Null, or nothing in
VB.NET, for this to work. I tried that, however, with the same result,
black image ...
DevContext = GetDC(WindowHandle)
''''''
ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height, SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)
'''''''' This line always returns zero for me, what gives?
Success = GetDIBits(DevContext, HBITMAP, 0, ImgHeight, ImgBits, ImgInfo,
DIB_RGB_COLORS)
''''''''
If Success = 0 Then Throw New Exception("The conversion from a regular
image to a FREEIMAGE failed ...!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error with FreeImage Conversion
code!")
End Try
End Function



大声笑,说我觉得FreeImage to .NET很容易。我有一个

的想法虽然*可能*简化了一些事情。怎么可能只是将.NET Image保存到内存流然后将图像加载到内存中的字节数组中的
?这样你就不必再做任何其他的东西了。我现在只是看看如何实现这一目标虽然

可能在明天有时因为我的头疼而无法解决问题!


Nick 。


Nak < a@a.com>在消息中写道

news:u7 ************** @ TK2MSFTNGP11.phx.gbl ...
LOL, saying that I think FreeImage to .NET is the easy bit. I''ve had an
idea though that *might* simplify things. How about possibly just saving
the .NET Image to memory stream and then loading the image into free image
from the byte array in memory? This way you won''t have to do any of the
other stuff. I''m just taking a look at how this can be achieved now though
may not have a solution until tomorrow sometimes as my head hurts!

Nick.

"Nak" <a@a.com> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
嗨Chris,

http://www.members.lycos.co .uk / nickpatemanpwp /

点击我自己的软件
点击FreeScript in VB.NET (您需要向下滚动到VB.NET

然后您将能够下载将FreeImage转换为.NET位图的示例,我'我相信它可以很容易地适应反向工作。
但是说,如果你自己提供所有数据和标题信息,使用Bitmaps *会有点棘手。

尼克。

克里斯托弗·库尔蒂斯·科伯< c _ ****** @ myrealbox.com>在留言中写道
新闻:%2 ** ************** @ TK2MSFTNGP15.phx.gbl ...
Hi Chris,

http://www.members.lycos.co.uk/nickpatemanpwp/

Click "My Own Software"
Click "FreeImage In VB.NET" (You will need to scroll down to the VB.NET
Section

You will then be able to download an example of converting FreeImage to
a .NET Bitmap, I''m sure it can be easily adapted to work in the reverse.
But saying that, working with Bitmaps *can* be a bit tricky if your having
to supply all of the data and header information yourself.

Nick.

"Christopher Kurtis Koeber" <c_******@myrealbox.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
亲爱的,
我想转换system.drawing.image或位图到FreeImage
位图。我正在使用下面的代码。注意:我遇到的问题似乎与FreeImage库本身无关,而不是Windows
API我在这方面做错了什么?这是我在下面使用的代码,但结果是黑色图像而不是我放入的图像。 有任何想法吗?非常感谢您的时间!
此致,Christopher Koeber

PS:FreeImage类是freeimage项目的一部分。您可以访问
http://freeimage.sourceforge.net 了解更多信息。

受保护的MainImage作为新的FreeImage
私有声明函数GetDIBits Lib" gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr,ByVal nStartScan As Int32,ByVal nNumScans As
Int32,ByVal lpBits As IntPtr,ByRef lpBI As BITMAPINFO,ByVal wUsage As
Int32)As Int32
私有声明函数GetObject Lib" gdi32.dll"别名GetObjectA
(ByVal hObject As IntPtr,ByVal nCount As Int32,ByRef lpObject As
GDIBITMAP)As Int32
Private Declare Function GetDC Lib" user32.dll" (ByVal hwnd As IntPtr)As
Int32
私有Const DIB_RGB_COLORS As Integer = 0
私有DevContext为整数

< StructLayout(LayoutKind.Sequential)> _
私有结构GDIBITMAP
公共bmType为Int32
公共bmWidth为Int32
公共bmHeight为Int32
公共bmWidthBytes为Int32
公共bmPlanes为Int16
Public bmBitsPixel As Int16
Public bmBits As Int32


公共函数ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap)As Int32
尝试
Dim SrcBitmap作为GDIBITMAP
Dim成功作为Int32
Dim ImgHeight作为整数
Dim ImgBits作为IntPtr
Dim ImgInfo作为BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP,Marshal.SizeOf(SrcBitmap),SrcBitmap)

''''''在freeimage来源,我告诉你在VB.NET中放入Null,或者什么都不用,这样才能工作。然而,我尝试了同样的结果,
黑色图像......
DevContext = GetDC(WindowHandle)
''''''

ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height,SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)

''''''''这行总是为我返回零,是什么给出的?
成功= GetDIBits(DevContext,HBITMAP,0,ImgHeight,ImgBits ,ImgInfo,
DIB_RGB_COLORS)
''''''''

如果成功= 0则抛出新例外(从常规
图像转换)到FREEIMAGE失败了......!>
Catch ex As Exception
MsgBox(ex.Message,MsgBoxStyle.Critical,FreeImage Conversion错误代码!)结束尝试
结束功能
Dear all,
I would like to convert a system.drawing.image or bitmap to a FreeImage
bitmap. I am using the code below. NOTE: the problem I am having doesn''t
seem to be with the FreeImage Library itself bit rather with the Windows
API calls. Am I doing something wrong on that end? This is the code that
I am using below, but the result is a black image and not the image that
I put in. Any ideas? Thank you very much for your time!
Sincerely,
Christopher Koeber

PS: The FreeImage Class is part of the freeimage project. You can visit
http://freeimage.sourceforge.net for more info.

Protected MainImage As New FreeImage
Private Declare Function GetDIBits Lib "gdi32.dll" (ByVal aHDC As Int32,
ByVal hBitmap As IntPtr, ByVal nStartScan As Int32, ByVal nNumScans As
Int32, ByVal lpBits As IntPtr, ByRef lpBI As BITMAPINFO, ByVal wUsage As
Int32) As Int32
Private Declare Function GetObject Lib "gdi32.dll" Alias "GetObjectA"
(ByVal hObject As IntPtr, ByVal nCount As Int32, ByRef lpObject As
GDIBITMAP) As Int32
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As
Int32
Private Const DIB_RGB_COLORS As Integer = 0
Private DevContext As Integer

<StructLayout(LayoutKind.Sequential)> _
Private Structure GDIBITMAP
Public bmType As Int32
Public bmWidth As Int32
Public bmHeight As Int32
Public bmWidthBytes As Int32
Public bmPlanes As Int16
Public bmBitsPixel As Int16
Public bmBits As Int32
End Structure

Public Function ConvertHBITMAPToFreeImage(ByVal WindowHandle As IntPtr,
ByVal ImageToConvert As Bitmap) As Int32
Try
Dim SrcBitmap As GDIBITMAP
Dim Success As Int32
Dim ImgHeight As Integer
Dim ImgBits As IntPtr
Dim ImgInfo As BITMAPINFO
Dim HBITMAP As IntPtr = ImageToConvert.GetHbitmap(Color.White)
GetObject(HBITMAP, Marshal.SizeOf(SrcBitmap), SrcBitmap)
'''''' On the freeimage sources, I wat told to put Null, or nothing in
VB.NET, for this to work. I tried that, however, with the same result,
black image ...
DevContext = GetDC(WindowHandle)
''''''
ConvertHBITMAPToFreeImage = MainImage.Allocate(ImageToConvert.Width,
ImageToConvert.Height, SrcBitmap.bmBitsPixel)
ImgHeight = MainImage.GetHeight(ConvertHBITMAPToFreeImage)
ImgBits = MainImage.GetBits(ConvertHBITMAPToFreeImage)
ImgInfo = MainImage.GetInfo(ConvertHBITMAPToFreeImage)
'''''''' This line always returns zero for me, what gives?
Success = GetDIBits(DevContext, HBITMAP, 0, ImgHeight, ImgBits, ImgInfo,
DIB_RGB_COLORS)
''''''''
If Success = 0 Then Throw New Exception("The conversion from a regular
image to a FREEIMAGE failed ...!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error with FreeImage Conversion
code!")
End Try
End Function




这篇关于使用FreeImage库....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆