Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Manipulating Bitmaps With GetDIBits


Hey,

I found alot of sourcecodes about this but every time i try to add it to my form something goes wrong.

i think its because i didnt understand completly how to use this API

i know u need the bitmap info and the scales of the pictures
(which btw , i didnt understand the diffrence between Width and ScaleWidth)

i also found out that if the scale is not pixels getdibits returens 0

can anyone show me the simplest source WITH EXPLANSIONS on how to use this API and SetDIBits

i just want to load a picture to Array and than to change the colors and write it again - i heard dibs are very fast


if someone can give me a BAS with made functions like

loadbitmaptoarray pic,bits()


its not as good as understanding it , but its something


10x




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Manipulating Bitmaps HARD!!
I've posted this question in Experts-exchange.com, but I thought I'd get a better variety of answers if I posted here as well.

  My original question:
Quote:I have a question that should set you thinking.

    I have a bitmap(a picute I took with a digital camera) that has some writing on it, well its a picture of some writing. The problem with the photo is that the background is a kind of yucky grey/brown colour, though i wrote it on a clean WHITE peice of paper.

I want to write a program that makes the background colour a colour of the users choice.

I don't even know where to start writeing this, can some one help?


I got an answer back saying I should use set/getpixel
so I replyed:
Quote:yes I could do that I could get the user to select the back colour on the picture then change/blankout all the pixels with that colour, but the background colour isn't the same colour.

hmmm, I could get the user to select the text colour(at its lightest), then only keep the pixels that are darker than it.

Could you help me put it into code, I dont know how to use Setpixel/getpixel.


Can anybody here help me with this?
Thanks



BoyIdiot

I never think of the future - it comes soon enough.
Albert Einstein
  

Manipulating Bitmaps In Rich Text Edit
I have a simple VB app that inserts a bitmap image into an Rich Text Edit control, and I am looking for a good way to control the scaling. It is simple for the user to do this manually -- they can simply grab the bitmap and resize it with the mouse, which modifies the RTF codes /objscalex and /objscaley. But, short of modifying the RTF code iteself (very inefficient), how can I get the RT Box to scale the bitmap to, say 50%?

Thanks,

Chris

OLE Bitmaps Ver. Long Binary Bitmaps
Hi,

I need to make a report that displays pictures stored in a data source. However, it seems that Crystal Report easily displays the picture if it was saved as OLE Bitmap. But mine was "Long Binary". Nothing is displayed in Crystal Report. How can I resolve this problem?

About GetDIBits
I was wondering how I would use GetDIBits to store arrays of pixels from clipboard after doing print screen. From these arrays of pixels than I will start searching for the pixels I want.

I searched online for tutorials and even read up on GetDIBits. But to dismay I failed to understand how to use it efficiently to make it work at all. I was hoping someone could provide me sample code.

GetDIBits
Hi I found an attachment from this site on using GetDIBits to rotate image.....

I want to use the function to convert the image into grayscale.....

But I having trouble accessing the color components.....

the GetDIBits reads the image pixels into bits(x,y) array...

bits array is declared as dim bits() as rgbQUAD

Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
end type

I have tried this
bits(x,y).rgbRed 'Red comp
bits(x,y).rgbGreen 'Green comp
bits(x,y).rgbBlue 'Blue comp

but when I compared the pixels color values with other program like PhotoShop program, it does look anything similar.....

Now when we call the GetDIBits(,,,,,,bits(0,0),,,,,,)
it this function scane the image pixels from top left downward.....????

Thanks....

GetDIBits
When getting the bits from a bitmap, they seem to be placed in a 3 dimensional byte array

Is there a good way to fit this in a single dimension byte array, so that when it is sent over a socket, its in the correct order as if it was written binary to file.

I am having trouble sending a 3 dimensional array from getdibits onto the network.

GetDIBits
Hi there,
I've a DIB Section in which there's a graphic.Now I want to get its bits using GetDIBits in vb.Can anybody help me in this..?

Regards,
Asim Siddiqui.

GetDIBits
I just want to print lines and polygon which are in a PictureBox control.

The GetDiBits function always (and i mean ALWAYS) return 0 wich mean that something went wrong. Even by pasting the MicroSoft code it return 0

Is this function still Working


SOS

How To Use GetDIBits And StretchDIBits?
Could you somebody tell me how to use API code?

Using The GetDIBits API Call
I am trying to load bitmap data from a form into a bitmap structure so that i can write it to disk. I have successfully used the BitBlt call to copy the bitmap from the form to a Memory DC (using a compatible bitmap) and I have then ensured that the bitmap isn't currently selected into the memory DC (since i read that GetDIBits doesn't work if the bitmap is currently selected into any DC's).

I have setup the BitmapInfoHeader and BitmapInfo structures using an array of 256 RGBQUAD structures. And I have specified the biBitCount value in the bitmapinfoheader structure to be 8 (256 colours).

I have used GlobalAlloc and GlobalLock calls to successfully allocate memory for the bitmap bits. To calculate the amount of memory to allocate for the bitmap i have simply multiplied the imageheight by the imagewidth by the number of bits per pixel (and multiplied this by 8 to get the number of byted reqd.) ...Is this correct?

Sofar so good....now when i call the GetDIBits function it is failing. As far as i can tell I am doing everything correctly. I am running VB6 Professional, on Win98.

Any Ideas Appreciated...

regards,
Michael Yates
michael@diginetix.com.au

Using The GetDIBits API Call
I am trying to load bitmap data from a form into a bitmap structure so that i can write it to disk. I have successfully used the BitBlt call to copy the bitmap from the form to a Memory DC (using a compatible bitmap) and I have then ensured that the bitmap isn't currently selected into the memory DC (since i read that GetDIBits doesn't work if the bitmap is currently selected into any DC's).

I have setup the BitmapInfoHeader and BitmapInfo structures using an array of 256 RGBQUAD structures. And I have specified the biBitCount value in the bitmapinfoheader structure to be 8 (256 colours).

I have used GlobalAlloc and GlobalLock calls to successfully allocate memory for the bitmap bits. To calculate the amount of memory to allocate for the bitmap i have simply multiplied the imageheight by the imagewidth by the number of bits per pixel (and multiplied this by 8 to get the number of byted reqd.) ...Is this correct?

Sofar so good....now when i call the GetDIBits function it is failing. As far as i can tell I am doing everything correctly. I am running VB6 Professional, on Win98.

Any Ideas Appreciated...

regards,
Michael Yates
michael@diginetix.com.au

How To Use The GetDIBits() Function ?
How to I use the GetDIBits() function to get every 64 bits of pixel on an image?
Although a pixel has 24 bits(RGB), but I need to get 64 bits which might be 2 pixels or 3 pixels at any one time.

Please help.

Dev.

Damned GetDIBits ! Damn It !
THIS **** CODE IS FREAKING ME OUT !

Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hdc As Long, _
ByVal hbmp As Long, _
ByVal uStartScan As Long, _
ByVal cScanLines As Long, _
ByVal lpvBits As Long, _
ByVal lpdi As Long, _
ByVal uUsage As Long)

Public Const DIB_RGB_COLORS = 1

Private Sub Form_Load()
ProgramDC = MonitorScreen.hdc
ScreenDC = GetWindowDC(0)
ImageDC = ImgField.hdc
End Sub

Call GetDIBits(ScreenDC, ScreenDC, 0, 0, pic(), DIB_RGB_COLORS)

THE ****ING VB SAID Argument not optional (Error 449)

**** IT

Bitmap Pixel Aceess With GetDiBits
Hi

Im doing a face detection project in which I capture a frame (face and background) from a video camera and save it as a bitmap picture. I then need to search the entire picture for non-skin colors and replace it with white, thus leaving just the face.

I need help on how to search for a specific pixel color in a bitmap and replace the pixel color with another colour. I wanna also save the new bitmap with the new pixel color. How do I manipulate each pixel and once its maniplulated how do I save it as a bitmap again to view.

I saved the original image as a device independent bitmap and I want to know how to access the pixels using GetDIbits.

This is my code so far

capGrabFrameNoStop(hwnd1);//grabs a frame from the video stream and fills the frame buffer
capFileSaveDIB(hwnd1,"orig.bmp");//saves the captured frame

GetDIBits, BitBlt? Finding An Image On The Screen.
Hi,
I'm trying to search the screen for a set bmp, basically I want to scan the screen until it finds a certain image, then return the coordinates of the image. I'm just not sure what the most appropriate or effective way of doing this is.

For instance, I have a picture of a Directory Icon. I want to be able to scan the screen, say on the desktop and it return the location of where it found the image.

Any theories or examples etc are much appreciated.

Cheers

Create STRING Buffer Of A GetDIBits And SetDIBits
If someone wanted to stream a image in a picture box to another picture box on a different computer on a local network and WITHOUT saving to the hard drive on either machine, how might I go by doing this?

I need the actual code for it, since I have no clue of how GetDIBits/SetDIBits can buffer into an actual "String" data format and not into a DC.

Does anyone have a code to do this?

Get Color Pixels From Desktop Into Array... GetDIBits
i want a way to get the pixels from the desktop into an array without the WICKED slow getpixel... so after TONS of research ive found you can do it with GetDIBits (atleast i believe so... im still trying to grasp the concept)

so ive used a few different references and msdn and my code looks like this so far

Code:
Private Sub Command2_Click()
Dim hDCSrc As Long, hDCDest As Long, hDCBmp As Long, lHandle As Long, lHandle1 As Long, lResult As Long, lBMap As Long, bInfo As BITMAPINFO, lDIB As Long
Dim CQ() As RGBQUAD
lHandle = GetDesktopWindow
If lHandle Then
    hDCSrc = GetWindowDC(lHandle)
    If hDCSrc Then
        hDCDest = CreateCompatibleDC(hDCSrc)
        If hDCDest Then
        DoEvents
            lBMap = CreateCompatibleBitmap(hDCDest, Screen.Width, Screen.Height)
            If lBMap Then
                lHandle1 = SelectObject(hDCDest, lBMap)
                If lHandle1 Then
                    BitBlt hDCDest, 0, 0, Screen.Width, Screen.Height, hDCSrc, 0, 0, vbSrcCopy
                    With bInfo.bmiHeader
                        .biSize = Len(bInfo.bmiHeader)
                        .biWidth = Screen.Width ' Width in pixels.
                        .biHeight = Screen.Height ' Height in pixels.
                        .biPlanes = 1 ' 1 color plane.
                        .biBitCount = 32 ' 24 bits per pixel.
                        .biCompression = BI_RGB ' No compression.
                        .biSizeImage = 0 ' Unneeded with no compression.
                        .biXPelsPerMeter = 0 ' Unneeded.
                        .biYPelsPerMeter = 0 ' Unneeded.
                        .biClrUsed = 0
                        .biClrImportant = 0
                    End With
                    hDCBmp = GetWindowDC(lHandle)
                    hDCBmp = CreateCompatibleDC(hDCBmp)
                    If hDCBmp Then
                        ReDim CQ(1 To Screen.Width / 15, 1 To Screen.Height / 15)
                        lResult = GetDIBits(hDCDest, lBMap, 0, Screen.Height / 15, CQ(1, 1), bInfo, DIB_RGB_COLORS)
                        MsgBox lResult
                    End If
                End If
            End If
        End If
    End If
End If
End Sub


with everything declared ... everything returns right except the lResult from GetDIBits ... anyone familiar with this and know how to help?

[Solved] - GetDIBits - Picturebox Pixel Retrieval
Hi VBcitizens,

I discovered a strange occurrence within an old project of mine and I can't get my head around why this is happening.

I'm using GetDIBits to retrieve the pixel data from a picturebox.
This has always worked fine untill I had a 499w 300h image in the picturebox.

Whenever I call GetDIBits then it raises an "memory could not be written" error. (or sometimes closes without any report)

I don't understand why a 500/300 image works and a 499/300 image doesn't when calling GetDIBits.

Anyone knowns what could be the cause of this?

part of source:
Code:
Option Explicit

Private Type RGBTRIPLE
   rgbBlue As Byte
   rgbGreen As Byte
   rgbRed As Byte
End Type

Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type
 
Private Type BITMAPINFOHEADER
    bmSize As Long
    bmWidth As Long
    bmHeight As Long
    bmPlanes As Integer
    bmBitCount As Integer
    bmCompression As Long
    bmSizeImage As Long
    bmXPelsPerMeter As Long
    bmYPelsPerMeter As Long
    bmClrUsed As Long
    bmClrImportant As Long
End Type
 
Private Type BITMAPINFO
    bmHeader As BITMAPINFOHEADER
    bmColors(0 To 255) As RGBTRIPLE
End Type

Private Const DIB_RGB_COLORS = 0

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, _
                                                                   ByVal nCount As Long, _
                                                                   ByRef lpObject As Any) _
                                                                   As Long

Private Declare Function GetDIBits Lib "gdi32" (ByVal hDC As Long, _
                                                ByVal hBitmap As Long, _
                                                ByVal nStartScan As Long, _
                                                ByVal nNumScans As Long, _
                                                lpBits As Any, _
                                                lpBI As BITMAPINFO, _
                                                ByVal wUsage As Long) _
                                                As Long

Private Type tIMG_DATA
    bm As BITMAP
    px() As Byte
End Type

Private Sub Form_Load()

    Me.ScaleMode = vbPixels
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True
    Picture1.AutoSize = True
    Picture1.Picture = LoadPicture(App.Path & "eetle.bmp")
    
End Sub

Private Sub Command1_Click()

    Dim myIMG As tIMG_DATA
    Get_ImageData Picture1, myIMG
    
End Sub

Private Sub Get_ImageData(PBox As PictureBox, thisIMG As tIMG_DATA)

    GetObject PBox.Image, Len(thisIMG.bm), thisIMG.bm
    
    Dim bmi As BITMAPINFO
    bmi.bmHeader.bmSize = 40
    bmi.bmHeader.bmPlanes = 1
    bmi.bmHeader.bmBitCount = 24
    bmi.bmHeader.bmCompression = 0
    bmi.bmHeader.bmWidth = thisIMG.bm.bmWidth
    bmi.bmHeader.bmHeight = thisIMG.bm.bmHeight
    
    ReDim thisIMG.px(0 To 2, 0 To thisIMG.bm.bmWidth - 1, 0 To thisIMG.bm.bmHeight - 1)
    
  ' error occurrence
    GetDIBits PBox.hDC, PBox.Image, 0, thisIMG.bm.bmHeight, thisIMG.px(0, 0, 0), bmi, DIB_RGB_COLORS
    
  ' no error occurrence when substracting 1 from the nNumScans,
  ' but then the pixel array is missing an edge...
  ' GetDIBits PBox.hDC, PBox.Image, 0, thisIMG.bm.bmHeight - 1, thisIMG.px(0, 0, 0), bmi, DIB_RGB_COLORS
    
End Sub


=============================================
aka Red2048.

Edited by - T48 - [RedPlanet] on 5/21/2007 5:36:32 PM

Converting Picture To Binaire Info To Send Through Winsocket With GetDIBits
GetDIBits ?? i read it everywhere use this to get a picturebox's info and send it over the winsock. i dont really know how to use this and how to reconvert it? i cant find any examples or something on it , basicly what i am trying to do is grab the user's desktop to a picture box of 320x200 and send it to a client wich will be able to see a small window of what the person is doing how to send it? any examples?

&"GetDIBits&" API Stucked In ActiveX ???
I have been writing activeX to get all RGB values for an image into an array using GetDIBits API

It runs fine in a standard form

but it can't get the values of RGB while i convert it into ActiveX.

Can anyone know wat's happening?

MODULE:
Public Declare Function GetDIBits Lib "GDI32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long

Public Type BITMAP '14 bytes
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Public Type BITMAPINFOHEADER '40 bytes
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImage As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed As Long
    biClrImportant As Long
End Type



USER CONTROLS:
Private Sub CreateFromPicture(sPic As IPicture)
Dim tB As BITMAP
GetObjectAPI sPic.Handle, Len(tB), tB
picHeight = tB.bmHeight
picWidth = tB.bmWidth

Dim bitmap_info As BITMAPINFO
Dim bytes_per_scanline As Integer
Dim pad_per_scanline As Integer
Dim pixels() As Byte



    With bitmap_info.bmiHeader 'start load picture data
        .biSize = 40
        .biHeight = -picHeight 'use negative to make top-down scan
        .biWidth = picWidth
        .biPlanes = 1
        .biBitCount = 32
        .biCompression = BI_RGB
        bytes_per_scanline = ((((.biWidth * .biBitCount) + 31) 32) * 4) 'get bytes
        pad_per_scanline = bytes_per_scanline - (((.biWidth * .biBitCount) + 7) 8) 'get pad
        .biSizeImage = bytes_per_scanline * Abs(.biHeight)
    End With

    ReDim pixels(1 To 4, 1 To picWidth, 1 To picHeight)

    GetDIBits Picture1.hdc, Picture1.Image, 0, picHeight, pixels(1, 1, 1), bitmap_info, DIB_RGB_COLORS
    

End Sub

Bitmaps
Hi,
Issit possible to add a bitmap image to the whole form?
As in the frame also takes in the picture...
Thanks.

Bitmaps And DC's And DIB's, Oh My!
Hey everyone. I had a question about graphics programming. I'm creating my own little game, kinda like a WW2 fighter pilot game. For this game I wanted to create my own special image format, which I did. It takes 24-bt bitmaps from a folder you specify, strings the raw data together, creates a header, compresses the file, and Whola! My very own image files.

The problem herein is that I have no idea how to load that raw data that I extract into a Device Context.

There was some code I found that you can edit the bytes in a DC, but you have to preload an image.

Is there a way to create one of a specified height/width and load the raw data into them?

XP Bitmaps
Hello There!

I'd like to know how to get the windows XP bitmaps.
When I say bitmaps I say the titlebar bitmap, the start menu bitmap, the xp controls bitmaps, etc...

thanks for reading and please help me

Bitmaps
I would like to be able to edit bitmaps in memory - so that maybe I could add a blavk pixel to the top right of a bitmap or some such - but I don't know how - can anyone tell me?
Thanks.

Bitmaps
how do i make sure that a picture is stored as a bitmap

(for transfer to plgblt :'(

Bitmaps From DLL
Hi,

I saw thread regarding Bitmaps In DLL.But i face following problem...

I have the dll which contains only bitmaps, i should not include any class or functions other than that resource file.

So how to retrive the images from DLL now,
I am using the following code, but it returns long data type..no idea how to proceed next..

"LoadBitmap" is API

Dim hInst As Long, lResult As Long
Dim Img As Image
Dim resString As String * 255
IntLocation = 301
hInst = LoadLibrary("MyDLL.dll")
lResult = LoadBitmap(hInst, "301")
lResult = StrPtr(lResult)
Picture1.Picture = lResult

Pls Help me out...


Thanks
Harish

Bitmaps In A Dll
anyone know how, if this is even possible, to store the bitmap images(.gif; .jpg; .bmp) in a dll that i can then call to load?

Bitmaps
Ok say I have 10 picboxes each containing 1 pixel of color. Is there a way I can arrange them into two rows of five pixels and then save the result as a bitmap? Thanks.

BITMAPS And DCs
I need to find the bmBits property from:

VB Code:
Private Type Bitmap    bmType As Long    bmWidth As Long    bmHeight As Long    bmWidthBytes As Long    bmPlanes As Integer    bmBitsPixel As Integer    bmBits As LongEnd Type

For a DC, I have stored the DC and the hBitmap values for when I created the DC and below is how i'v created the DC.

VB Code:
Dim DC As LongDim hBitmap As Long     DC = CreateCompatibleDC(0)    hBitmap = CreateCompatibleBitmap(frmMain.hdc, Width, Height)    'Throw bitmap into DC...    SelectObject DC, hBitmap

I know that I can get the Bitmap structure from the code below but don't know how to do it if I'm not using a pictureBox.

VB Code:
GetObjectAPI Pic1.Picture, Len(bmp), bmp

Thanx for any help.

Bitmaps
For a 24-bit uncompessed bitmap, would the bfSize parameter of the BITMAPFILEHEADER type be:

Len(BITMAPFILEHEADER) + Len(BITMAPINFOHEADER) + (Width * Height * 3)

?

Bitmaps
Hi Everyone,

What is the secret to creating transparent backgrounds on bitmaps? I am trying to get this to work in the image list. The only bitmaps I can get to work are those that I pull out of the Microsoft program folders. Any help would be appreciated. Thank you.

Bitmaps
if im using 16col bmp's in a program, can i change the palette of all of the bitmaps on a form to that of a newly created bmp, or change indevidual colors in all the bmps.

Bitmaps In VB
In Visual Basic, how to create, display and modify a .BMP files?
Thanks!
Sasha
shkolns@attbi.com
(323)-304-4359



Bitmaps
Hi Everybody,

I have been searching for putting bitmaps on menu and i came across this http://support.microsoft.com/default.aspx?scid=kb;en-us;71281
But when i tried to compile it i get a prob Const TRUE = -1, FALSE = 0
 it Compiles but i dont get the bitmaps on the menu and then i come out of the program.

Am i missing something or is it that the code is incomplete.

Thank u all

Regards,
Lis

Bitmaps?
Is there a control that will let me put an editable bitmap on a form?

I know how to load an existing bmp at runtime, but I need to know how to save that bitmap. I've been working on making a function that creates a .bmp header, and its comming along ok, but if this is already done I hope someone tells me. But I need to make an extremely simple version of paint to add in to a game editor I'm making. Thanks for the help.

--NoxEternal

Bitmaps
Does any one knows how to change a BMP file to the old format. When you try to display a picture in BMP format made with Kodak Imaging(Win98) it bring this error "Invalid Format". If you run the same program in Win95 it works well.

Right know i have a program that works with pictures using IMGSCAN.OCX to control the scanner. But when it saves the picture the app running in Win98 cand not display the picture.

Any help will be strongely apreciated

adcomp - Puerto Rico

Put Bitmaps Into DLL
How can I build a DLL which contains bitmap resources ??

Mirroring Bitmaps
My application prints labels to various printers. There is a mirroring option which diverts the bitmap from the standard printer dc to a memory compatible dc. What I have works fine under XP but not Win 98. The code in question is as follows:

Public Sub CreateMirrorDc(ByVal wid As Long, ByVal ht As Long)
' This creates a compatible dc with the printer.
' Use this for mirroring
Dim lngMyWidth As Long
Dim lngMyHeight As Long


lngMyWidth = wid / printer.TwipsPerPixelX
lngMyHeight = ht / printer.TwipsPerPixelY
' Create a compatible device context to the output
hMemDC = CreateCompatibleDC(lPrintDC) ' This will return the printer dc
bHaveMemDc = True
hMemBM = CreateCompatibleBitmap(lPrintDC, lngMyWidth, lngMyHeight)
hOrigBM = SelectObject(hMemDC, hMemBM)
etc......
etc.....


When I step this code in a Win98 environment I get hMemBm =0 . There is a problem. I have checked Err.LastDLLError but this is 0. I have seen conflicting info regarding the device context passed to CreateCompatibleBitmap. Should it be the DC used to create the memory dc or should it be the memory dc?

Does anyone have any suggestions

Monochrome Bitmaps
Ok, heres the problem,

I have NO idea how to even begin this. here's what i do know.

I have a long string of binary characters, I want to take said string, 1 bit at a time, and turn it into a monochromatic bitmap, literally only black and white. Its a math thing, I want to see what patterns are made by a specific number generator thing i have. regardless of that. I think i need to use GetPixel and SetPixel, but I'm not sure. Just a friendly Shove in the right direction with a Example would be wildly appreciated. Thanks

~Kerm

Bitmaps In Memory
Hello,
I would like to store about 800 bitmaps in picture objects in memory. At one point, I was curious how many bitmaps my computer (which has 512 Mbs of RAM) could hold in memory. It was able to hold around 9,000 until it said it was out of memory. However, Ctrl+Alt+Del said that there was still hundreds of Mbs of RAM available. So, why couldn't the computer hold more bitmaps? Is some other memory besides RAM being used?

I would like to get to the bottom of this because I don't know if 800 bitmaps is too many to store in memory or not. It's not too many on my newer computer, but maybe it would be on older computers.
Thanks

GDI+ Example 6 Streaming Bitmaps
OnErr0r,

I saw your GDI+ example #6 in the code library on streaming bitmaps.
It looks interesting and I would like to find out more about this but having never done anything with streaming before I found myself a bit out of my depth when reading your code.

I tried searching on the internet for more infomation but pretty much everything I found was for C++ or C# and I dont really understand those languages either.

I was wondering if you could perhaps update your example and show in a bit more detail how it could be used.

Could it for example be used to download images from the internet? eg a bitmap.LoadFromURL function? I would like to see the load and send from streams as well that you suggested which might be able to be used with winsock.

I suspect you are a busy man but thought there was no harm in asking.

Stretching Bitmaps
how can you strecth bitmaps in vb, it would help if you included how to do it transparently.

eg. Paintpicture

Saving Bitmaps
Im Trying to make my own paint how would i go about saving, lets say im starting from scratch so i know all the ways to save

Break Out The Bitmaps! =P
Okay, here's the given situation:

I have created a class that contains a function which loads a bitmap into memory, from a file into a newly created DC etc., and returns all the info using a UDT, and all is working just fine. There's only one thing that I need to figure out though before this class is just about finished...

I want to retrieve the dimensions (width and height, preferably in pixels) of the loaded image. I doubt I could use the GetObject API function with the BITMAP type structure to obtain this information, because the only handles that this class creates are Device Context handles, no hWnd handles (that I know of). This is a very lightweight class, so I'm trying to find a way to go about this using only API functions.

I read all over the forum for related issues, and the closest thing I found requires an actual hWnd handle to pass into the 1st parameter of the GetObject API function, with 'Len(BMPInfo)' and 'BMPInfo' as the 2nd and 3rd parameters. 'BMPInfo' represents the BITMAP type structure, which would be filled after using that technique.

Any ideas?

EDIT: Please note that these images can be placed anywhere on the screen, so I can't limit myself to using 'Form1.hWnd' or something for an hWnd handle either.

Comparing Bitmaps
hi,

i was wondering how many methods of comparing bitmaps there are?

i mean, can you compare each pixel using DCs only? or should i use createcompatiblebitmap to make an array, which i can then compare to another bitmaps array?

thx

Bitmaps And Pixels
I got a huge picture I load into a image (a map). How can I show parts of it using pixel coordinates? E.g I know I want to start looking at 400x250 and stop at 500x450 ? PaintPicture looks like it but I can't figure out how to retrieve the pictures width and height.

Menu Bitmaps
Hi Guys,

Im going through an example in one of my books for adding images to my menus.

Although I havent quite grasped all the code I have a little code running with my icons by simply changing some of the examples code.

The example only shows how to change the first menu (Usually the FILE menu in most apps)
So if I were to add icons for the next menu(Say the EDIT menu) how do i code this.

I thought if i just kept incrimenting the "menuPos" up one it would just move through the menus but nope.

Any help is appreciated.
Thanks again.

Here is what I have for doing this so far


Code:
' ******************************
' ******************************
' ** MASTERING VB6 **
' ** by Evangelos Petroutos **
' ** SYBEX, **
' ******************************
' ******************************
Option Explicit

Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (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
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Const SRCCOPY = &HCC0020
Const MF_BYPOSITION = &H400&
Const MF_BITMAP = &H4&
Const MF_STRING = &H0&


Private Sub Form_Load()
Dim Width As Integer, Height As Integer
Dim hTmpDC As Long, hMenuID As Long
Dim hBitmap As Long, retValue As Long
Dim tmpID As Long
Dim fileName As String
Dim menuPos As Integer, menuID As Long

'Set menu position and file name
menuPos = 0
fileName = App.Path & "addstaff.gif"
Picture1.Picture = LoadPicture(fileName)
Width = 150
Height = 16
'Get handle to menu
hMenuID = GetSubMenu(GetMenu(Me.hwnd), menuPos)
'Create device context to store bitmap
hTmpDC = CreateCompatibleDC(Picture1.hdc)
'Create the bitmap for the picture
hBitmap = CreateCompatibleBitmap(Picture1.hdc, Width, Height)
'Select bitmap into temporary dc
tmpID = SelectObject(hTmpDC, hBitmap)
'Copy contents from picture control to DC
retValue = BitBlt(hTmpDC, 0, 0, Width, Height, _
Picture1.hdc, 0, 0, SRCCOPY)
'Deselect bitmap
tmpID = SelectObject(hTmpDC, tmpID)
'Modify the menu
menuID = GetMenuItemID(hMenuID, menuPos)
retValue = ModifyMenu(hMenuID, menuPos, MF_BYPOSITION Or MF_BITMAP Or MF_STRING, _
menuID, hBitmap)
'Second menu item
menuPos = 1
fileName = App.Path & "affix.gif"
Picture1.Picture = LoadPicture(fileName)
'Create the bitmap for the picture
hBitmap = CreateCompatibleBitmap(Picture1.hdc, Width, Height)
'Select bitmap into temporary dc
tmpID = SelectObject(hTmpDC, hBitmap)
retValue = BitBlt(hTmpDC, 0, 0, Width, Height, _
Picture1.hdc, 0, 0, SRCCOPY)
tmpID = SelectObject(hTmpDC, tmpID)
menuID = GetMenuItemID(hMenuID, menuPos)
retValue = ModifyMenu(hMenuID, menuPos, MF_BYPOSITION Or MF_BITMAP, _
menuID, hBitmap)
'Third menu item
menuPos = 2
fileName = App.Path & "clubs.gif"
Picture1.Picture = LoadPicture(fileName)
'Create the bitmap for the picture
hBitmap = CreateCompatibleBitmap(Picture1.hdc, Width, Height)
'Select bitmap into temporary dc
tmpID = SelectObject(hTmpDC, hBitmap)
retValue = BitBlt(hTmpDC, 0, 0, Width, Height, _
Picture1.hdc, 0, 0, SRCCOPY)
tmpID = SelectObject(hTmpDC, tmpID)
menuID = GetMenuItemID(hMenuID, menuPos)
retValue = ModifyMenu(hMenuID, menuPos, MF_BYPOSITION Or MF_BITMAP, _
menuID, hBitmap)
'Fourth menu item
menuPos = 3
fileName = App.Path & "contacts.gif"
Picture1.Picture = LoadPicture(fileName)
'Create the bitmap for the picture
hBitmap = CreateCompatibleBitmap(Picture1.hdc, Width, Height)
'Select bitmap into temporary dc
tmpID = SelectObject(hTmpDC, hBitmap)
retValue = BitBlt(hTmpDC, 0, 0, Width, Height, _
Picture1.hdc, 0, 0, SRCCOPY)
tmpID = SelectObject(hTmpDC, tmpID)
menuID = GetMenuItemID(hMenuID, menuPos)
retValue = ModifyMenu(hMenuID, menuPos, MF_BYPOSITION Or MF_BITMAP, _
menuID, hBitmap)

'Clean up
retValue = DeleteDC(hTmpDC)
End Sub

Bitmaps In Menu
Hallo frends;

How can i store bitmap or icon symbols in a visual basic menu.

Have a sample for me

thanks

Hannes

Zooming Bitmaps
I have added a zooming function to my project from a previous thread, and am having some issues.

If I try to zoom by a factor greater than 9, I get the following error:

Cant Create AutoRedraw Image

I have seen apps zoom in much closer than this, so what am I doing wrong?

Also, if I select another zoom factor and click the Show button, the new zoom
image is not displayed (unless I close the window first).
I tried Image.Refresh in a few different spots, but that did not fix the problem.

I am attaching the project.

Copyright 2005-08 www.BigResource.com, All rights reserved