Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6 VB.NET
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 10-Apr-13 0:39am
Edited 10-Apr-13 0:57am
v2

1 solution

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

Solution 1

Hi,
 
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.
 
Cheers
  Permalink  
v2
Comments
AnnuBhai at 10-Apr-13 6:32am
   
actually i want in vb6
AnnuBhai at 10-Apr-13 6:32am
   
plz help me frnd
AnnuBhai at 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 at 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 at 10-Apr-13 8:27am
   
how yaar
plz send me
AnnuBhai at 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 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
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