控制尺寸以毫米为单位

时间:2015-05-16 17:37:38

标签: c# wpf size dpi

我正在尝试在我用C#(WPF)编程的应用程序中显示地图。有没有办法将PresentationSource source = PresentationSource.FromVisual(myControl); double dpiX = 96.0f * source.CompositionTarget.TransformToDevice.M11; double sizeInCentiMeter = myControl.Width / dpiX * 2.54; 大小从像素转换为厘米?

我试过这段代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct AdjListNode
{
    int dest;
    struct AdjListNode *next;
} ;


// declare list of pointers to nodes
static struct AdjListNode **head = NULL;


struct AdjListNode *create_node(int dest)
{
    struct AdjListNode *nod;

    nod = malloc(sizeof(struct AdjListNode));
    if(nod==NULL)
    {
        perror(" malloc failed" );
        printf("Problems at memory allocation!");
        exit(-1);
    }

    // implied else, malloc successful

    nod->dest = dest;
    nod->next = NULL;
    return nod;
} // end function: create_node



int main( void )
{
    int n; //number of graph nodes
    int i; //just a counter
    int dest = -1; //it's actually the "name" of the nodes. They  must all be positive so I started negative


    printf("The number of nodes of the graph: ");
    if( 1 != scanf("%d", &n) )
    { // then scanf failed
        perror( "scanf for number of nodes failed" );
        exit( -1 );
    }

    // implied else, scanf successful

    // set ptr to list of node pointers
    head = malloc(n*sizeof(struct AdjList*));
    if( NULL == head )
    { // then malloc failed
        perror( "malloc failed for list of pointers to nodes" );
        exit( -1 );
    }

    // implied else, malloc successful

    // initialize list of pointers (makes for easier cleanup, especially when a failure occurs
    memset( head, 0x00, n*sizeof(struct AdjList*) );

    /* We make a loop for the nodes and each node has a while thru which I make the links */
    for(i=0;i<n;i++)
    {
        printf("Enter Dest value for %d of %d:", i, n);

        if( 1 != scanf("%d", &dest) ) // note %d will skip over leading white space like newlines
        { // then scanf failed
            perror( "scanf for dest value failed" );
            exit(-1);
        }

        // implied else, scanf successful

        if(dest>=0)
        {
             head[i] = create_node(dest);
        }
        else
        {
            printf( "Dest value must be >= 0\n" );
        }

        //verificam daca vrem sa continuam

        // inchidem lista
    } // end for

    return 0;
} // end function: main

但我得到的大小有误差百分比。我的意思是实际尺寸总是比计算尺寸大约0.25。

您可以假设dpi = 96。

0 个答案:

没有答案