Click here to Skip to main content
11,921,316 members (61,163 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB6 VB VB.NET
here i have 1 applicaton which is capture photo whch is store as jpg (through HD cam)

and i have another app which in vb6

in that i have picture box ,when i try to show that image in vb6 picture box , then it generates an error "Invalid picture"

Show i know it a bit depth problem of images

actual picture have 32 bit depth and vb6 want 24 bit depth size of images
so how to convert 32 to 24 bit depth of image through vb6
Posted 10-Apr-13 0:39am
Edited 10-Apr-13 0:57am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


You need to check Encoder.ColorDepth field.

MSDN - Encoder.ColorDepth

Some sample code:
using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetColorDepth
    public static void Main()
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;
        // Create a Bitmap object based on a BMP file.
        myBitmap = new Bitmap(@"C:\Documents and Settings\All Users\Documents\My Music\music.jpg");
        // Get an ImageCodecInfo object that represents the TIFF codec.
        myImageCodecInfo = GetEncoderInfo("image/jpeg");
        // Create an Encoder object based on the GUID 
        // for the ColorDepth parameter category.
        myEncoder = Encoder.ColorDepth;
        // Create an EncoderParameters object. 
        // An EncoderParameters object has an array of EncoderParameter 
        // objects. In this case, there is only one 
        // EncoderParameter object in the array.
        myEncoderParameters = new EncoderParameters(1);
        // Save the image with a color depth of 24 bits per pixel.
        myEncoderParameter =
            new EncoderParameter(myEncoder, 24L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes24bpp.jpeg", myImageCodecInfo, myEncoderParameters);
    private static ImageCodecInfo GetEncoderInfo(String mimeType)
        int j;
        ImageCodecInfo[] encoders;
        encoders = ImageCodecInfo.GetImageEncoders();
        for(j = 0; j < encoders.Length; ++j)
            if(encoders[j].MimeType == mimeType)
                return encoders[j];
        return null;

For VB6, you can use SetBitmapBits function.

'API for bitmap get/setting array
Private Declare Function GetBitmapBits Lib "gdi32" _
(ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" _
(ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)

Private 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
Private ImgHeader As BITMAP
Private Sub Command1_Click()
Picture1.Picture = LoadPicture("c:\emp4bit.bmp")
GetObject Picture1.Image, Len(ImgHeader), ImgHeader
MsgBox "Color depth = " & ImgHeader.bmBitsPixel & " bits"
MsgBox "Bytes per row = " & ImgHeader.bmWidthBytes
End Sub

You will need to investigate further.

AnnuBhai 10-Apr-13 6:32am
actually i want in vb6
AnnuBhai 10-Apr-13 6:32am
plz help me frnd
AnnuBhai 10-Apr-13 6:35am
José Amílcar Ferreira Casimiro i want to conversion 32 t 24 in vb6
I improve the solution. It is not the final code but puts you on track.
AnnuBhai 10-Apr-13 7:17am
actually this one for finding bit depth of images not changing
To change you will have to use SetBitmapBits function.
AnnuBhai 10-Apr-13 8:27am
how yaar
plz send me
AnnuBhai 10-Apr-13 8:52am
help me plzzzzzzzzzz

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 583
1 Dave Kreskowiak 245
2 phil.o 160
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,951
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,171
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100