Results 1 to 5 of 5

Thread: Problem saving/opening bitmap file.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    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
    ------------------------------------------------------

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Maybe the .Save default is not Bitmap..try

    bmp.Save("c:\test.bmp", ImageFormat.Bitmap)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Slight revision. tested this and it works

    bmp.Save("c:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks!

    Hey thank you!!!!

    Prompt reply and quick revision on the code!!!!

    Works great!!!

    Man this forum is a find!!!!!!!!

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width