Tagging photo with problem

3

I've made a code that labels a jpg , by typing the client's site address in the image footer.

The Problem: Some photos the text is coming giant as if it were source 72px instead of source 12px

Correct Photo Link

Link wrong PHOTO

See that both photos are vertical, but the same text "www.sigasoftware.com.br" is different in size.

When running the VS debug it seems that all values are similar, not justifying this source of this size, I need some hint of how I can try to find the problem

Follow part of the code for my class manipula_foto.cs

private void EstampaTexto(int _largura, int phHeight, Graphics grPhoto)
{
    Font crFont = null;
    SizeF crSize = new SizeF();

    crFont = new Font("verdana", 12, FontStyle.Bold);
    crSize = grPhoto.MeasureString(_textoetiqueta, crFont);

    //imagem a 5% da altura, debaixo para cima.
    int yPixlesFromBottom = (int)(phHeight * .05);

    // Agora que temos um tamanho de ponto usar a altura das cordas Copyrights
    // para determinar a coordenada y para desenhar a série de fotografia
    float yPosFromBottom = ((phHeight - 10) - (crSize.Height / 2));

    //Determinar a coordenada x calculando o centro da largura da imagem
    float xCenterOfImg = (_largura / 2);

    //definindo posição central do texto
    StringFormat StrFormat = new StringFormat();
    StrFormat.Alignment = StringAlignment.Center;

    // retangulo de fundo
    Brush brush = new SolidBrush(Color.FromArgb(120, 255, 255, 255));
    grPhoto.FillRectangle(brush, 0, yPosFromBottom, _largura, 20);

    //Texto Frente
    SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
    grPhoto.DrawString(_textoetiqueta,                 //string of text
        crFont,                                   //font
        semiTransBrush,                           //Brush
        new PointF(xCenterOfImg, yPosFromBottom),  //Position
        StrFormat);                               //Text alignment
}
    
asked by anonymous 14.10.2014 / 21:23

2 answers

6

You are confusing the measurements. The Font constructor you are using expects the size in units em which is a relative measure and not in points px which is an absolute measure. View the documentation .

See more about it in another question .

Try using a different constructor that specifies the pixel unit . Choose the type Pixel . I can not tell you that it is the most appropriate solution to the answer quoted above, but it is a way that can "solve" your problem.

    
14.10.2014 / 21:39
3

Thanks to Maniero's answer , I have resolved by placing the type of unit of measure used.

crFont = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Pixel);
    
14.10.2014 / 22:20