?
Solved

Bitmap related.....

Posted on 2005-04-03
12
Medium Priority
?
1,081 Views
Last Modified: 2013-12-03
Hi all,
         I am developing for Windows CE.NET 4.1 device..... I need to load large Bitmaps(roughly 5000x5000 pixels 4 bit 16 clor image) in my project..... I have done quite a bit of development in eVB and here is how I have managed it....

The following function loads the Bitmap in memory(using CreateCompatibleDC(0)) and returns the hDC of the Memory DC..... Now displaying this image on the screen is really easy as it involves only a call to Bitblt....

    Public Declare Function GetDC Lib "Coredll" (ByVal hWnd As Long) As Long
    Public Declare Function BitBlt Lib "Coredll" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Public Declare Function SHLoadDIBitmap Lib "Coredll" (ByVal szFileName As String) As Long
    Public Declare Function CreateCompatibleDC Lib "Coredll" (ByVal hdc As Long) As Long
    Public Declare Function DeleteObject Lib "Coredll" (ByVal hObject As Long) As Long
    Public Declare Function SelectObject Lib "Coredll" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Public Declare Function GetLastError Lib "Coredll" () As Long
    Public Declare Function DeleteDC Lib "Coredll.dll" (ByVal hdc As Long) As Long
    Public Declare Function StretchBlt Lib "Coredll.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Public Declare Function CreateCompatibleBitmap Lib "Coredll.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long


    Public Function ImageLoad(ByVal imlHDC As Long, ByVal imlImageName As String) ' Handle to the old bitmap in the DC, for clear up:
        Dim m_hBmpOld As Long  ' Handle to bitmap creating with ImageLoad
        Dim pName As String       'Path to loading image

        pName = imlImageName
         Call DeleteObject(hbmp)
        imlHDC = CreateCompatibleDC(0)
        hbmp = SHLoadDIBitmap(pName)
        If hbmp = 0 Then
            Call DeleteObject(imlHDC)
            imlHDC = 0
            MsgBox("Can't load BMP image" & GetLastError)
            Exit Function
        End If
        m_hBmpOld = SelectObject(imlHDC, hbmp)
        Call DeleteObject(m_hBmpOld)
        ImageLoad = imlHDC
    End Function

This was working quite fine in eVB but I am having quite a big headache in converting it so that it can run in VB.NET compact framework......

Note that I have also tried to use the Bitmap class but I have got no success with it......
Dim flag As New Bitmap("c:\Map.bmp")

creates error(because Map.bmp is about 7 MB) but if I load a small bmp it works OK......

So All I am asking is for a way to load a 7MB BMP into memory DC and get a handle to it so that I can bitblt it on a picture box...... If someone can modify my existing code or give some other suggestions ????

and I am developing for Windows CE.NET i.e using the Compact Framework and I am really a novice in VB.NET development.....

Imran
0
Comment
Question by:imarshad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13740120
What is the error?  Out of memory, perhaps?

There is a limit to the size of images within GDI+

Bob
0
 
LVL 13

Author Comment

by:imarshad
ID: 13740446
I get an ArgumentException "Could not find resource assembly"..
But if I try this with a smaller BMP say 800x600 then it works.... What is wrong?

Imran
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13740585
What happens if you convert this Bitmap image to JPG?

Bob
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Author Comment

by:imarshad
ID: 13740821
>>convert this Bitmap image to JPG?

Not tried so far...... But I think reading a JPG involves more processing then reading a BMP..... And also these BMP's are basically maps of different cities of my area and I have geo-referenced them. So maybe JPG is not that much a good choice...

Anyways have you seen my code that I used in eVB.....Can it be converted to be used with VB.NET Compact Framework???
I somewhere studied that the API's can be imported/used in VB.NET..... How can this be done?
Also I am having one big problem..... In eVB and VB6 we used to have hDC to be used in API's like Bitblt etc. But in VB.NET I have seen Intptr....Whats the difference between them?

Imran
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13751890
Here's a good explanation of what IntPtr is:

Exploring general functions of the Marshal class:
http://www.codeproject.com/vb/net/Marshal.asp

"IntPtr:  .NET's platform-dependent representation of a memory address"

Getting an HDC using Graphics.GetHdc:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawinggraphicsclassgethdctopic.asp

Bob
0
 
LVL 13

Author Comment

by:imarshad
ID: 13770483
OK I have found the problem.... The problem was in the declaration of the API's..... In eVB a long was of 32bits while in VB.NET the Long is 64 bits..... So I needed to declare the API's using Integer rather then Long..... Now my image is loading using the function above..... I have one last problem.... Can you tell me how to get the hDC of a picturebox??? I have seen this code on some tutorial

Dim GrpObj as Graphics = PictureBox1.CreateGraphics
Dim MyDeviceContext as IntPtr ' Creating the  variable to keep the DC address
MyDeviceContext = GrpObj.GetHdc()

But this is not working in Compact Framework..... I get error on GrpObj.GetHdc() as there is not GetHdc member for GrpObj..... Can you suggest me how to use Bitblt in VB.NET while blitting on a Picturebox???? or alternativley finding hDC or IntPtr of a picturebox in Compact Framework?????

and as far as the Bitmap class is concerned I think I will post a new question for this.....

Imran
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13780422
Have you seen this?  Would it help?

Saving a Control Image to a Bitmap File:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/scibf.asp

Bob
0
 
LVL 13

Author Comment

by:imarshad
ID: 13905243
I am still lost in this question..... Since I was more busy in learning Oracle and my other project so I wasn't able to reply to this question earlier.... But now I am in need of some solution to this problem..... All I want to know is a procedure to find the hDC of a picturebox in VB.NET compact framework.....  Can you help me or should I ask another question so that more people can also take a look at the question (As this question is no more in the top page)....

Imran
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13914245
I can't find anything that would be useful.

Bob
0
 
LVL 13

Author Comment

by:imarshad
ID: 13942612
Finally I got it.... The key was to first find the hwnd of my form. Here is the code I used

        Me.Capture = True
        Dim hwnd As Integer = GetCapture()
        picDC = GetWindowDC(hwnd, PictureBox1.Top, PictureBox1.Left)
        Me.Capture = False

where GetWindowDC function is declared as

    Function GetWindowDC(ByVal hWnd As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
        Dim ChildWnd As Integer
        ChildWnd = ChildWindowFromPoint(hWnd, x, y)
        GetWindowDC = GetDC(ChildWnd)
    End Function

Imran
0
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 14016044
Question Closed, 500 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question