|
-
Jul 8th, 2003, 01:14 PM
#1
Thread Starter
Fanatic Member
Problem saving/opening bitmap file.
This code works and saves the bmp file but when I try to open the file in MSPaint I get the error "Paint cannot read this file. This is not a bitmap file or is not currently supported". I can however open the file in a freeware image viewer called IfranView and I can insert and paste the file into MSWord. Why won't paint open the file? Is there something I can do in the code to make it a better bitmap?
Thanks....see code below....
-----------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
Dim bmp As Bitmap
bmp = Hardcopy.CreateBitmap(TextBox1)
bmp.Save("c:\test.bmp")
End Sub
End Class
Public Class Win32
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Const SRCCOPY As Integer = &HCC0020
End Class
Public Class Hardcopy
Public Shared Function CreateBitmap(ByVal Control As Control) As Bitmap
Dim gDest As Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer
Dim hWnd As Integer = Control.Handle.ToInt32
CreateBitmap = New Bitmap(Control.Width, Control.Height)
gDest = gDest.FromImage(CreateBitmap)
hdcSrc = Win32.GetWindowDC(hWnd)
hdcDest = gDest.GetHdc
Win32.BitBlt(hdcDest.ToInt32, 0, 0, Control.Width, Control.Height, hdcSrc, 0, 0, Win32.SRCCOPY)
gDest.ReleaseHdc(hdcDest)
Win32.ReleaseDC(hWnd, hdcSrc)
End Function
End Class
------------------------------------------------------
-
Jul 8th, 2003, 01:16 PM
#2
Maybe the .Save default is not Bitmap..try
bmp.Save("c:\test.bmp", ImageFormat.Bitmap)
-
Jul 8th, 2003, 01:25 PM
#3
Slight revision. tested this and it works
bmp.Save("c:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
-
Jul 8th, 2003, 01:54 PM
#4
Thread Starter
Fanatic Member
Thanks!
Hey thank you!!!!
Prompt reply and quick revision on the code!!!!
Works great!!!
Man this forum is a find!!!!!!!!
-
Jul 8th, 2003, 01:58 PM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|