Question

J'ai besoin de récolte une image sans changer son rapport d'aspect.Je prends la photo de Canon1100D en utilisant eDSDK.Image capturée: largeur= 1920 et hauteur= 1280

La ration de l'aspect est 1,5 .Mais j'ai besoin d'une image quel rapport qualité-prix est 1,33 .


// convert into processing resolution (1600,1200) 

Image<Bgr, byte> runtime_frm = new Image<Bgr, byte>(frame.ToBitmap(1600,1200));

// also in bitmap processing 

// Bitmap a = new Bitmap(runtime_frm.ToBitmap());  
// Bitmap b = new Bitmap(a, new Size(1600,1200));

Il redimensionnement de l'image afin que le rapport d'image de l'image soit modifié, mais cela crée un stress dans l'image.Je dois recadrer l'image (1920x1280) à (1600x1200) en runtime.

Comment puis-je faire cela par programme?toute idée

Était-ce utile?

La solution

 public void Crop(Bitmap bm, int cropX, int cropY,int cropWidth,int cropHeight)
 {
       var rect = new System.Drawing.Rectangle(cropX,cropY,cropWidth,cropHeight);

       Bitmap newBm = bm.Clone(rect, bm.PixelFormat);

       newBm.Save("image2.jpg");
 }

Peut-être quelque chose comme ça?

source

Autres conseils

C'est ma solution pour le recadrage centré.


Bitmap CenterCrop(Bitmap srcImage, int newWidth, int newHeight)
{
     Bitmap ret = null;

     int w = srcImage.Width;
     int h = srcImage.Height;

     if ( w < newWidth || h < newHeight)
     {
           MessageBox.Show("Out of boundary");
           return ret;
     }

     int posX_for_centerd_crop = (w - newWidth) / 2;
     int posY_for_centerd_crop = (h - newHeight) / 2;

     var CenteredRect = new Rectangle( posX_for_centerd_crop, 
                             posY_for_centerd_crop,  newWidth, newHeight);

     ret = srcImage.Clone(imageCenterRect, srcImage.PixelFormat);

     return ret;
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top