Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i have 1 vb.net 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
Updated 9-Apr-13 23:57pm
v2

1 solution

Hi,

You need to check Encoder.ColorDepth field.

MSDN - Encoder.ColorDepth

Some sample code:
C#
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.

Cheers
 
Share this answer
 
v2
Comments
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
José Amílcar Casimiro 10-Apr-13 7:04am    
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900