Convertir image jpeg en niveaux de gris

nicop93 Messages postés 3 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 4 mai 2011 - 3 mai 2011 à 16:33
nicop93 Messages postés 3 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 4 mai 2011 - 4 mai 2011 à 13:05
Bonjour, je réalise une application mobile pour un smartphone (windows mobile 6) qui va devoir lire des code-barres. J'utilise des boites de dialogues pour la réaliser

Pour l'instant, j'ai réussi à coder la partie qui me permet d'utiliser la caméra du smartphone et de prendre une photo. j'ai utiliser l'API SHCAMERACAPTURE.
J'ai aussi coder la partie qui stock et affiche l'image.

J'aimerais convertir l'image en niveaux gris. Votre aide serait la bienvenue, je suis perdu sur cette partie.

voici une partie du code c++ de mon projet.

//Capture d'une image avec caméra du smartphone
void CcameraDlg::OnBnClickedButton3()
{
// Capture de l'image
SHCAMERACAPTURE shcc;
ZeroMemory(&shcc,sizeof(SHCAMERACAPTURE));
shcc.cbSize= sizeof(SHCAMERACAPTURE);
shcc.hwndOwner= m_hWnd;
shcc.pszInitialDir = TEXT("\\My Documents");
shcc.pszDefaultFileName = TEXT("test.jpg");
shcc.pszTitle = TEXT("Camera");
shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_ALL;
// Résolution 2M (1600*960) 3M (2048*1232) 5M (2592*1552)
// Resolution L (640*384) par defaut
shcc.nResolutionWidth = IMG_WIDTH;
shcc.nResolutionHeight = IMG_HEIGHT;
shcc.nVideoTimeLimit = 1;
shcc.Mode = CAMERACAPTURE_MODE_STILL;
shcc.StillQuality = CAMERACAPTURE_STILLQUALITY_HIGH;
HRESULT H=SHCameraCapture(&shcc);

}

//Affichage de l'image capturée en mode normal
void CcameraDlg::OnBnClickedButton6()
{
CDC * pDC = GetDC();
HBITMAP Hbitmap=SHLoadImageFile(_T("\\My Documents\\test.jpg"));
if(Hbitmap)
{

CBitmap bitmap;
bitmap.Attach(Hbitmap);

BITMAP bmpInfo;
bitmap.GetBitmap(&bmpInfo);

CDC bitmapDC;
bitmapDC.CreateCompatibleDC(pDC);
bitmapDC.SelectObject(&bitmap);
CRect RC;
GetClientRect(&RC);
pDC->StretchBlt(0, 0, RC.Width(), RC.Height(), &bitmapDC,
0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, SRCCOPY);
bitmapDC.DeleteDC();
bitmap.DeleteObject();
}
}



//Conversion et affichage l'image en niveau de gris
void CcameraDlg::OnBnClickedButton1()
{

}

3 réponses

nicop93 Messages postés 3 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 4 mai 2011
3 mai 2011 à 19:12
une précision, l'image jpeg a une résolution de 2MégaPixel.
0
CGSI3 Messages postés 416 Date d'inscription vendredi 22 février 2008 Statut Membre Dernière intervention 7 janvier 2018 1
3 mai 2011 à 22:04
Bonjour,
En passant sur le site, j'ai vu ta question.
(Je suis d'habitude en vb.net)
Je ne sais pas si tu peux le convertir .
Bonne soirée CGSI3
  Public Function MakeImageGrayscale() As Bitmap
      '  Auteur: Inconnu  But: Methode pour Convertir une image en niveau de gris 
      Dim cMatrix As New ColorMatrix(New Single()() _
          {New Single() {0.299, 0.299, 0.299, 0, 0}, _
          New Single() {0.587, 0.587, 0.587, 0, 0}, _
          New Single() {0.114, 0.114, 0.114, 0, 0}, _
          New Single() {0, 0, 0, 1, 0}, _
          New Single() {0, 0, 0, 0, 1}})

      Dim imageAttrib As New ImageAttributes
      imageAttrib.SetColorMatrix(cMatrix)
      MakeImageGrayscale = Bitmap.Clone
      Dim gr As Graphics = Graphics.FromImage(MakeImageGrayscale)      ' Apply the grayscale image attriBute
      gr.DrawImage(MakeImageGrayscale, New Rectangle(0, 0, MakeImageGrayscale.Width, MakeImageGrayscale.Height), 0, 0, MakeImageGrayscale.Width, MakeImageGrayscale.Height, GraphicsUnit.Pixel, imageAttrib)
      gr.Dispose()
   End Function
0
nicop93 Messages postés 3 Date d'inscription jeudi 10 juin 2010 Statut Membre Dernière intervention 4 mai 2011
4 mai 2011 à 13:05
Je ne sais pas convertir du basic en c++. J'aimerais bien un autre avis
0
Rejoignez-nous