영어 알파벳 중 어떤 문자가 가장 많은 픽셀을 차지합니까?
문장의 문자 수를 기반으로 일부 동적 프로그래밍을 시도하고 있습니다. 영어 알파벳 중 어떤 문자가 화면에서 가장 많은 픽셀을 차지합니까?
흠, 보자 :
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccccc
dddddddddddddddddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
ffffffffffffffffffffffffffffffffffffffffffffff
gggggggggggggggggggggggggggggggggggggggggg
ㅋㅋㅋ ㅋㅋㅋ ㅋㅋㅋ
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
lllllllllllllllllllllllllllllllllllllllllllll
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
oooooooooooooooooooooooooooooooooooooooo
pppppppppppppppppppppppppppppppppppppppppppp
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ssssssssssssssssssssssssssssssssssssssss
ttttttttttttttttttttttttttttttttttttttttttt
uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
zzzzzz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WWWWWWWWWWWWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
승.
물론 이것은 어리석은 실험적 실험입니다. 어떤 문자가 가장 넓은 지에 대한 답은 없습니다. 글꼴에 따라 다릅니다. 따라서 환경에 대한 해답을 찾으려면 비슷한 실험적 실험을 수행해야합니다. 그러나 사실 대부분의 글꼴은 동일한 규칙을 따르며 대문자 W가 가장 넓습니다.
Ned Batchelder의 놀랍도록 실용적인 대답에 더해, 나는 여기에 숫자에 대해 궁금해했기 때문에 :
0000000000000000000000000000000000000000
1111111111111111111111111111111111111111
2222222222222222222222222222222222222222
3333333333333333333333333333333333333333333
4444444444444444444444444444444444444444444
5555555555555555555555555555555555555555
6666666666666666666666666666666666666666666
7777777777777777777777777777777777777777777
8888888888888888888888888888888888888888
99999999999999999999999999999999999999999999
프로그래밍 솔루션은 어떻습니까?
var capsIndex = 65;
var smallIndex = 97
var div = document.createElement('div');
div.style.float = 'left';
document.body.appendChild(div);
var highestWidth = 0;
var elem;
for(var i = capsIndex; i < capsIndex + 26; i++) {
div.innerText = String.fromCharCode(i);
var computedWidth = window.getComputedStyle(div, null).getPropertyValue("width");
if(highestWidth < parseFloat(computedWidth)) {
highestWidth = parseFloat(computedWidth);
elem = String.fromCharCode(i);
}
}
for(var i = smallIndex; i < smallIndex + 26; i++) {
div.innerText = String.fromCharCode(i);
var computedWidth = window.getComputedStyle(div, null).getPropertyValue("width");
if(highestWidth < parseFloat(computedWidth)) {
highestWidth = parseFloat(computedWidth);
elem = String.fromCharCode(i);
}
}
div.innerHTML = '<b>' + elem + '</b>' + ' won';
나는 그 편지 W
가 가장 넓다고 믿는다 .
대문자 "M"은 일반적으로 가장 넓습니다.
플랫폼에 따라 어떻게 든 width 속성을 사용하여 문자열 또는 DrawText () 함수에서 "getWidth"하는 방법이있을 수 있습니다.
필요한 글꼴을 사용한 간단한 알고리즘을 만든 다음 알파벳을 통해 작은 구성으로 저장하거나 초기화 할 때 A에서 Z까지의 루프로 그렇게 열심히 계산하지 않았습니다.
또한 글꼴에 따라 다릅니다. 나는 1-2 년 전에 Processing and Helvetica를 사용하여 픽셀을 늘리는 순서대로 ILJTYFVCPAXUZKHSEDORGNBQMW입니다. 아이디어는보고있는 글꼴로 캔버스에 텍스트를 그리고 픽셀 수를 세운 다음 HashMap 또는 Dictionary로 정렬하는 것입니다.
물론 이것은 너비가 아닌 픽셀 영역을 계산하기 때문에 사용과 직접 관련이 없을 수도 있습니다. 약간 과잉 일 수도 있습니다.
void setup() {
size(30,30);
HashMap hm = new HashMap();
fill(255);
PFont font = loadFont("Helvetica-20.vlw");
textFont(font,20);
textAlign(CENTER);
for (int i=65; i<91; i++) {
background(0);
text(char(i),width/2,height-(textDescent()+textAscent())/2);
loadPixels();
int white=0;
for (int k=0; k<pixels.length; k++) {
white+=red(pixels[k]);
}
hm.put(char(i),white);
}
HashMap sorted = getSortedMap(hm);
String asciiString = new String();
for (Iterator<Map.Entry> i = sorted.entrySet().iterator(); i.hasNext();) {
Map.Entry me = (Map.Entry)i.next();
asciiString += me.getKey();
}
println(asciiString); //the string in ascending pixel order
}
public HashMap getSortedMap(HashMap hmap) {
HashMap map = new LinkedHashMap();
List mapKeys = new ArrayList(hmap.keySet());
List mapValues = new ArrayList(hmap.values());
TreeSet sortedSet = new TreeSet(mapValues);
Object[] sortedArray = sortedSet.toArray();
int size = sortedArray.length;
// a) Ascending sort
for (int i=0; i<size; i++) {
map.put(mapKeys.get(mapValues.indexOf(sortedArray[i])), sortedArray[i]);
}
return map;
}
Chrome- W의 Arial 30px가 이깁니다 .
xxx가 게시 한 솔루션과 비슷한 글꼴 너비를 계산하는 솔루션이 Alex Michael이 자신의 블로그에 게시했습니다 (재미있게 여기에 나를 연결했습니다).
요약:
- Helvetica의 경우 상위 3 개 문자는 M (2493 픽셀), W (2414) 및 B (1909)입니다.
- Mac과 함께 제공된 글꼴 세트의 경우 결과는 M (2217.51 ± 945.19), W (2139.06 ± 945.29) 및 B (1841.38 ± 685.26)와 거의 동일합니다.
원본 게시물 : http://alexmic.net/letter-pixel-count/
암호:
# -*- coding: utf-8 -*-
from __future__ import division
import os
from collections import defaultdict
from math import sqrt
from PIL import Image, ImageDraw, ImageFont
# Make a lowercase + uppercase alphabet.
alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet += ''.join(map(str.upper, alphabet))
def draw_letter(letter, font, save=True):
img = Image.new('RGB', (100, 100), 'white')
draw = ImageDraw.Draw(img)
draw.text((0,0), letter, font=font, fill='#000000')
if save:
img.save("imgs/{}.png".format(letter), 'PNG')
return img
def count_black_pixels(img):
pixels = list(img.getdata())
return len(filter(lambda rgb: sum(rgb) == 0, pixels))
def available_fonts():
fontdir = '/Users/alex/Desktop/English'
for root, dirs, filenames in os.walk(fontdir):
for name in filenames:
path = os.path.join(root, name)
try:
yield ImageFont.truetype(path, 100)
except IOError:
pass
def letter_statistics(counts):
for letter, counts in sorted(counts.iteritems()):
n = len(counts)
mean = sum(counts) / n
sd = sqrt(sum((x - mean) ** 2 for x in counts) / n)
yield letter, mean, sd
def main():
counts = defaultdict(list)
for letter in alphabet:
for font in available_fonts():
img = draw_letter(letter, font, save=False)
count = count_black_pixels(img)
counts[letter].append(count)
for letter, mean, sd in letter_statistics(counts):
print u"{0}: {1:.2f} ± {2:.2f}".format(letter, mean, sd)
if __name__ == '__main__':
main()
It will depend on the font. I would create a small program in a programming language you're most comfortable with, where you draw each letter of the alphabet into a n times m sized bitmap. Initialize each pixel with white. Then count the number of white pixels after you've drawn each letter and save that number. The highest number you find is the one you're looking for.
EDIT: If you're in fact just interested in which one takes up the largest rectangle (but it looks like you're really after that, not the pixels), you can use various API calls to find the size, but that depends on your programming language. In Java, for example, you would use the FontMetrics class.
I know the accepted answer here is W, W is for WIN.
However, in this case, W is also for Width. The case study used employed a simple width test to examine pixels, but it was only the width, not the total pixel count. As an easy counter example, the accepted answer assumes that O and Q take up the same amount of pixels, yet they only take up the same amount of space.
Thus, W takes up the most space. But, is it all the pixels it's cracked up to be?
Let's get some empirical data. I created imgur images from the following B, M and W. I then analyzed their pixel count (see below), here are the results:
B : 114 pixels
M : 150 pixels
W : 157 pixels
Here is how I fed them into canvas and analyzed the raw pixel data from the images.
var imgs = {
B : "//i.imgur.com/YOuEPOn.png",
M : "//i.imgur.com/Aev3ZKQ.png",
W : "//i.imgur.com/xSUwE7w.png"
};
window.onload = function(){
for(var key in imgs){(function(img,key){
var Out = document.querySelector("#"+key+"Out");
img.crossOrigin = "Anonymous";
img.src=imgs[key];
img.onload = function() {
var canvas = document.querySelector('#'+key);
(canvas.width = img.width,canvas.height = img.height);
var context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
var data = context.getImageData(0, 0, img.width, img.height).data;
Out.innerHTML = "Total Pixels: " + data.length/4 + "<br>";
var pixelObject = {};
for(var i = 0; i < data.length; i += 4){
var rgba = "rgba("+data[i]+","+data[i+1]+","+data[i+2]+","+data[i+3]+")";
pixelObject[rgba] = pixelObject[rgba] ? pixelObject[rgba]+1 : 1;
}
Out.innerHTML += "Total Whitespace: " + pixelObject["rgba(255,255,255,255)"] + "<br>";
Out.innerHTML += "Total Pixels In "+ key +": " + ((data.length/4)-pixelObject["rgba(255,255,255,255)"]) + "<br>";
};
})(new Image(),key)}
};
<table>
<tr>
<td>
<canvas id="B" width="100%" height="100%"></canvas>
</td>
<td id="BOut">
</td>
</tr>
<tr>
<td>
<canvas id="M" width="100%" height="100%"></canvas>
</td>
<td id="MOut">
</td>
</tr>
<tr>
<td>
<canvas id="W" width="100%" height="100%"></canvas>
</td>
<td id="WOut">
</td>
</tr>
</table>
It depends on the font. Crossed zero for example takes up considerably more than a regular one.
But if one could put up a guess, I'd go with X or B.
'IT story' 카테고리의 다른 글
JQuery를 사용하여 Div에서 CSS 제거 (0) | 2020.05.27 |
---|---|
libv8 설치 오류 : 오류 : gem 기본 확장을 빌드하지 못했습니다. (0) | 2020.05.27 |
넷 플로우 레코드가 8 진수를 얻을 수 없음 (jnca) (0) | 2020.05.27 |
Windows Phone 7 시작하기 (0) | 2020.05.27 |
GPU 프로그래밍 소개 (0) | 2020.05.27 |