的例子介绍了在VB6.0中使用GDI+ TLB 1.05绘制图形和文本的方法。
但是如何将绘制的结果保存成支持Alpha通道的Png文件呢?
例如我在屏幕上用GdipDrawString方法在graphics对象(这里实际上是一个Long变量)上绘制了平滑的文字,如何将graphics对象上的图像存成支持Alpha通道的透明Png图像呢?
我知道在VB.NET非常容易实现,但在VB6.0中借助GDI+ TLB 1.05如何做?
要配合提供的SaveDib方法么?
请高手解惑。
17 个解决方案
#1
给我mail地址,我发给你。
#2
sui_x@163.com
先谢过了。
先谢过了。
#3
查收,一下发给你4个例子。
#4
谢谢,我先研究研究.
#5
还没收到...
#6
先顶顶,分啊
#7
Modest(塞北雪貂)·(偶最欣赏楼主的分) :
你给我的几个例子我都见过。可都没有如何将graphics中的图片存储的例子。
另外,存储图片需要SaveAsImageFile函数?但SaveAsImageFile函数通过Image参数存储图片,而不是graphics
那如何将graphics转换为image进行存储???
你给我的几个例子我都见过。可都没有如何将graphics中的图片存储的例子。
另外,存储图片需要SaveAsImageFile函数?但SaveAsImageFile函数通过Image参数存储图片,而不是graphics
那如何将graphics转换为image进行存储???
#8
我需要的是存储我在graphics中绘制的图片。例如我就画了一条线,透明度为50%,则要求存储的Png图片也只包含一条透明度为50%的线(其他地方全透明),而不是一条线叠加在窗体背景上的不透明Png或Bmp。这在VB.NET中轻而易举。
而我几乎找遍了有关VB6.0操作Png的例子,就是找不到一个将绘制的图形保存为Png图片的例子,郁闷死啦。。。
而我几乎找遍了有关VB6.0操作Png的例子,就是找不到一个将绘制的图形保存为Png图片的例子,郁闷死啦。。。
#9
通过对象浏览器查看发现有这样的几个函数:
Function GdipSaveGraphics(Graphics As Long, State As Long) As GpStatus
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
如何使用?
Function GdipSaveGraphics(Graphics As Long, State As Long) As GpStatus
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
如何使用?
#10
http://blog.chenoe.com/blog/article.asp?id=2055
#11
我还没能搞懂graphics对象和Image对象的区别。
我要画线、画平滑文字、画图片并将最终的和成结果显示到窗体上都用到了graphics对象。所以我认为我画的图,就是不包括窗体背景的那一部份在graphics里。而我要把它存成Png图片而不是仅仅显示在窗体上。
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
应当是用于保存应当是用于保存图片的函数,但参数是Image。
我现在要做的工作应该是
graphics-〉Image
但我不知道怎么做。。。
我要画线、画平滑文字、画图片并将最终的和成结果显示到窗体上都用到了graphics对象。所以我认为我画的图,就是不包括窗体背景的那一部份在graphics里。而我要把它存成Png图片而不是仅仅显示在窗体上。
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
应当是用于保存应当是用于保存图片的函数,但参数是Image。
我现在要做的工作应该是
graphics-〉Image
但我不知道怎么做。。。
#12
就是把我绘制在Form上的前景图弄到Png文件中。。。
#13
Dim graphics As Long, bitmap As Long
Dim lngHeight As Long, lngWidth As Long
Dim opaquePen As Long, semiTansPen As Long
GdipError GdipCreateFromHDC(Me.hDC, graphics)
GdipError GdipLoadImageFromFile("c:\Default.png", bitmap)
GdipError GdipDrawImageRect(graphics, bitmap, 0, 0, 45 , 45)
例如上面那段代码加载了一个Png图片按指定的大小放在了窗体上。
我还可以继续用
GdipDrawString(graphics, "XXXXX", -1, curFont, rcLayout, 0, brush)
的方法在graphics中写字。。。
我要把最后叠加的结果(不包含背景)存储到Png文件上。而这些内容在graphics中,不再Image中。。。
Dim lngHeight As Long, lngWidth As Long
Dim opaquePen As Long, semiTansPen As Long
GdipError GdipCreateFromHDC(Me.hDC, graphics)
GdipError GdipLoadImageFromFile("c:\Default.png", bitmap)
GdipError GdipDrawImageRect(graphics, bitmap, 0, 0, 45 , 45)
例如上面那段代码加载了一个Png图片按指定的大小放在了窗体上。
我还可以继续用
GdipDrawString(graphics, "XXXXX", -1, curFont, rcLayout, 0, brush)
的方法在graphics中写字。。。
我要把最后叠加的结果(不包含背景)存储到Png文件上。而这些内容在graphics中,不再Image中。。。
#14
到www.mndsoft.com找~
#15
我想关键是通过Image来创建graphics对象,而不是Hdc。就如同在VB.net中通过graphics对象的FromImage方法一样。
但这里graphics是Long,它没有FromImage方法,也没有类似graphicsFromImage或GdipCreateFromImage的函数提供……
但这里graphics是Long,它没有FromImage方法,也没有类似graphicsFromImage或GdipCreateFromImage的函数提供……
#16
MSDN中的相关说明如下。VB中如何实现阿??
Graphics::FromImage Method
--------------------------------------------------------------------------------
The FromImage method creates a Graphics object that is associated with a specified Image object.
Syntax
static Graphics *FromImage( Image *image
);
Parameters
image
[in] Pointer to an Image object that will be associated with the new Graphics object.
Return Value
This method returns a pointer to the new Graphics object.
Remarks
This method fails if the Image object is based on a metafile that was opened for reading. The Image::Image(filename, useEmbeddedColorManagement) and Metafile::Metafile(filename) constructors open a metafile for reading. To open a metafile for recording, use a Metafile constructor that receives a device context handle.
This method also fails if the image has one of the following pixel formats:
PixelFormatUndefined
PixelFormatDontCare
PixelFormat1bppIndexed
PixelFormat4bppIndexed
PixelFormat8bppIndexed
PixelFormat16bppGrayScale
PixelFormat16bppARGB1555
Example
The following example calls the Graphics::FromImage method to create a Graphics object that is associated with an Image object. The call to Graphics::FillEllipse does not paint on the display device; instead, it alters the bitmap of the Image object. The call to Graphics::DrawImage displays the altered bitmap.
VOID Example_FromImage(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object from a PNG file.
Image image(L"Mosaic.png");
// Create a Graphics object that is associated with the image.
Graphics* imageGraphics = Graphics::FromImage(&image);
// Alter the image.
SolidBrush brush(Color(255, 0, 0, 255));
imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);
// Draw the altered image.
graphics.DrawImage(&image, 30, 20);
delete imageGraphics;
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
Graphics::FromImage Method
--------------------------------------------------------------------------------
The FromImage method creates a Graphics object that is associated with a specified Image object.
Syntax
static Graphics *FromImage( Image *image
);
Parameters
image
[in] Pointer to an Image object that will be associated with the new Graphics object.
Return Value
This method returns a pointer to the new Graphics object.
Remarks
This method fails if the Image object is based on a metafile that was opened for reading. The Image::Image(filename, useEmbeddedColorManagement) and Metafile::Metafile(filename) constructors open a metafile for reading. To open a metafile for recording, use a Metafile constructor that receives a device context handle.
This method also fails if the image has one of the following pixel formats:
PixelFormatUndefined
PixelFormatDontCare
PixelFormat1bppIndexed
PixelFormat4bppIndexed
PixelFormat8bppIndexed
PixelFormat16bppGrayScale
PixelFormat16bppARGB1555
Example
The following example calls the Graphics::FromImage method to create a Graphics object that is associated with an Image object. The call to Graphics::FillEllipse does not paint on the display device; instead, it alters the bitmap of the Image object. The call to Graphics::DrawImage displays the altered bitmap.
VOID Example_FromImage(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object from a PNG file.
Image image(L"Mosaic.png");
// Create a Graphics object that is associated with the image.
Graphics* imageGraphics = Graphics::FromImage(&image);
// Alter the image.
SolidBrush brush(Color(255, 0, 0, 255));
imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);
// Draw the altered image.
graphics.DrawImage(&image, 30, 20);
delete imageGraphics;
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
#17
是否可用GdipGetImageGraphicsContext函数???
得到的Graphics类,含有FromImage方法。
Public Sub FromImage(Image As GDIPImage)
Dispose
SetStatus GdipGetImageGraphicsContext(Image.nativeImage, m_gfx)
End Sub
得到的Graphics类,含有FromImage方法。
Public Sub FromImage(Image As GDIPImage)
Dispose
SetStatus GdipGetImageGraphicsContext(Image.nativeImage, m_gfx)
End Sub
#1
给我mail地址,我发给你。
#2
sui_x@163.com
先谢过了。
先谢过了。
#3
查收,一下发给你4个例子。
#4
谢谢,我先研究研究.
#5
还没收到...
#6
先顶顶,分啊
#7
Modest(塞北雪貂)·(偶最欣赏楼主的分) :
你给我的几个例子我都见过。可都没有如何将graphics中的图片存储的例子。
另外,存储图片需要SaveAsImageFile函数?但SaveAsImageFile函数通过Image参数存储图片,而不是graphics
那如何将graphics转换为image进行存储???
你给我的几个例子我都见过。可都没有如何将graphics中的图片存储的例子。
另外,存储图片需要SaveAsImageFile函数?但SaveAsImageFile函数通过Image参数存储图片,而不是graphics
那如何将graphics转换为image进行存储???
#8
我需要的是存储我在graphics中绘制的图片。例如我就画了一条线,透明度为50%,则要求存储的Png图片也只包含一条透明度为50%的线(其他地方全透明),而不是一条线叠加在窗体背景上的不透明Png或Bmp。这在VB.NET中轻而易举。
而我几乎找遍了有关VB6.0操作Png的例子,就是找不到一个将绘制的图形保存为Png图片的例子,郁闷死啦。。。
而我几乎找遍了有关VB6.0操作Png的例子,就是找不到一个将绘制的图形保存为Png图片的例子,郁闷死啦。。。
#9
通过对象浏览器查看发现有这样的几个函数:
Function GdipSaveGraphics(Graphics As Long, State As Long) As GpStatus
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
如何使用?
Function GdipSaveGraphics(Graphics As Long, State As Long) As GpStatus
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
如何使用?
#10
http://blog.chenoe.com/blog/article.asp?id=2055
#11
我还没能搞懂graphics对象和Image对象的区别。
我要画线、画平滑文字、画图片并将最终的和成结果显示到窗体上都用到了graphics对象。所以我认为我画的图,就是不包括窗体背景的那一部份在graphics里。而我要把它存成Png图片而不是仅仅显示在窗体上。
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
应当是用于保存应当是用于保存图片的函数,但参数是Image。
我现在要做的工作应该是
graphics-〉Image
但我不知道怎么做。。。
我要画线、画平滑文字、画图片并将最终的和成结果显示到窗体上都用到了graphics对象。所以我认为我画的图,就是不包括窗体背景的那一部份在graphics里。而我要把它存成Png图片而不是仅仅显示在窗体上。
Function GdipSaveImageToFile(Image As Long, Filename As String, ClsidEncoder As CLSID, EncoderParams As EncoderParameters) As GpStatus
应当是用于保存应当是用于保存图片的函数,但参数是Image。
我现在要做的工作应该是
graphics-〉Image
但我不知道怎么做。。。
#12
就是把我绘制在Form上的前景图弄到Png文件中。。。
#13
Dim graphics As Long, bitmap As Long
Dim lngHeight As Long, lngWidth As Long
Dim opaquePen As Long, semiTansPen As Long
GdipError GdipCreateFromHDC(Me.hDC, graphics)
GdipError GdipLoadImageFromFile("c:\Default.png", bitmap)
GdipError GdipDrawImageRect(graphics, bitmap, 0, 0, 45 , 45)
例如上面那段代码加载了一个Png图片按指定的大小放在了窗体上。
我还可以继续用
GdipDrawString(graphics, "XXXXX", -1, curFont, rcLayout, 0, brush)
的方法在graphics中写字。。。
我要把最后叠加的结果(不包含背景)存储到Png文件上。而这些内容在graphics中,不再Image中。。。
Dim lngHeight As Long, lngWidth As Long
Dim opaquePen As Long, semiTansPen As Long
GdipError GdipCreateFromHDC(Me.hDC, graphics)
GdipError GdipLoadImageFromFile("c:\Default.png", bitmap)
GdipError GdipDrawImageRect(graphics, bitmap, 0, 0, 45 , 45)
例如上面那段代码加载了一个Png图片按指定的大小放在了窗体上。
我还可以继续用
GdipDrawString(graphics, "XXXXX", -1, curFont, rcLayout, 0, brush)
的方法在graphics中写字。。。
我要把最后叠加的结果(不包含背景)存储到Png文件上。而这些内容在graphics中,不再Image中。。。
#14
到www.mndsoft.com找~
#15
我想关键是通过Image来创建graphics对象,而不是Hdc。就如同在VB.net中通过graphics对象的FromImage方法一样。
但这里graphics是Long,它没有FromImage方法,也没有类似graphicsFromImage或GdipCreateFromImage的函数提供……
但这里graphics是Long,它没有FromImage方法,也没有类似graphicsFromImage或GdipCreateFromImage的函数提供……
#16
MSDN中的相关说明如下。VB中如何实现阿??
Graphics::FromImage Method
--------------------------------------------------------------------------------
The FromImage method creates a Graphics object that is associated with a specified Image object.
Syntax
static Graphics *FromImage( Image *image
);
Parameters
image
[in] Pointer to an Image object that will be associated with the new Graphics object.
Return Value
This method returns a pointer to the new Graphics object.
Remarks
This method fails if the Image object is based on a metafile that was opened for reading. The Image::Image(filename, useEmbeddedColorManagement) and Metafile::Metafile(filename) constructors open a metafile for reading. To open a metafile for recording, use a Metafile constructor that receives a device context handle.
This method also fails if the image has one of the following pixel formats:
PixelFormatUndefined
PixelFormatDontCare
PixelFormat1bppIndexed
PixelFormat4bppIndexed
PixelFormat8bppIndexed
PixelFormat16bppGrayScale
PixelFormat16bppARGB1555
Example
The following example calls the Graphics::FromImage method to create a Graphics object that is associated with an Image object. The call to Graphics::FillEllipse does not paint on the display device; instead, it alters the bitmap of the Image object. The call to Graphics::DrawImage displays the altered bitmap.
VOID Example_FromImage(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object from a PNG file.
Image image(L"Mosaic.png");
// Create a Graphics object that is associated with the image.
Graphics* imageGraphics = Graphics::FromImage(&image);
// Alter the image.
SolidBrush brush(Color(255, 0, 0, 255));
imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);
// Draw the altered image.
graphics.DrawImage(&image, 30, 20);
delete imageGraphics;
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
Graphics::FromImage Method
--------------------------------------------------------------------------------
The FromImage method creates a Graphics object that is associated with a specified Image object.
Syntax
static Graphics *FromImage( Image *image
);
Parameters
image
[in] Pointer to an Image object that will be associated with the new Graphics object.
Return Value
This method returns a pointer to the new Graphics object.
Remarks
This method fails if the Image object is based on a metafile that was opened for reading. The Image::Image(filename, useEmbeddedColorManagement) and Metafile::Metafile(filename) constructors open a metafile for reading. To open a metafile for recording, use a Metafile constructor that receives a device context handle.
This method also fails if the image has one of the following pixel formats:
PixelFormatUndefined
PixelFormatDontCare
PixelFormat1bppIndexed
PixelFormat4bppIndexed
PixelFormat8bppIndexed
PixelFormat16bppGrayScale
PixelFormat16bppARGB1555
Example
The following example calls the Graphics::FromImage method to create a Graphics object that is associated with an Image object. The call to Graphics::FillEllipse does not paint on the display device; instead, it alters the bitmap of the Image object. The call to Graphics::DrawImage displays the altered bitmap.
VOID Example_FromImage(HDC hdc)
{
Graphics graphics(hdc);
// Create an Image object from a PNG file.
Image image(L"Mosaic.png");
// Create a Graphics object that is associated with the image.
Graphics* imageGraphics = Graphics::FromImage(&image);
// Alter the image.
SolidBrush brush(Color(255, 0, 0, 255));
imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);
// Draw the altered image.
graphics.DrawImage(&image, 30, 20);
delete imageGraphics;
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
#17
是否可用GdipGetImageGraphicsContext函数???
得到的Graphics类,含有FromImage方法。
Public Sub FromImage(Image As GDIPImage)
Dispose
SetStatus GdipGetImageGraphicsContext(Image.nativeImage, m_gfx)
End Sub
得到的Graphics类,含有FromImage方法。
Public Sub FromImage(Image As GDIPImage)
Dispose
SetStatus GdipGetImageGraphicsContext(Image.nativeImage, m_gfx)
End Sub