问题描述
这里我有1个vb.net应用程序,这是捕获照片whch以jpg存储(通过高清摄像头)
和我有另一个应用程序,在vb6
,我有图片框,当我尝试在vb6图片框中显示该图像,然后它生成错误无效的图片
显示我知道图像有点深度问题
实际图片有32位深度,vb6想要24位深度图像
所以如何通过vb6转换32到24位图像深度
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
推荐答案
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;
}
}
对于VB6,你可以使用。
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
这篇关于如何在vb.net中减少图像的位深度(JPG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!