I'm using Graphics.DrawString to draw a word inside a box. The boxes have a pre-defined minimum width which is large enough to accomodate the word.
Code:
RectangleF behaviorRect = new RectangleF(bodyRect.Left + bodyRect.Width / 8,
bodyRect.Top + bodyRect.Height / 8,
bodyRect.Width * 3 / 4,
bodyRect.Height * 3 / 4);
g.DrawRectangle(bluePen, bodyRect.Left + bodyRect.Width / 8,
bodyRect.Top + bodyRect.Height / 8,
bodyRect.Width * 3 / 4,
bodyRect.Height * 3 / 4);
g.DrawString("Behavior", textFont, blueBrush, behaviorRect, centerFormat);
On every Windows system this application has been tried on, it works fine. But one guy's Win 7 laptop is wrapping the text. Any ideas about why it would do this? The font is Verdana, and it appears to be using the correct font in the image.
Got it. The person in question had set his fonts to render at +25% size in the control panel. So the short answer to my question is, "yes".
Related
I'm using Octave 5.2 and can create a 640 x 480 x 3 image from an array of RGB values using meshgrid and reshape but is there a better way of doing this? (code is below) I tried using cat and imresize with nearest but the array is 640x480 not 640x480x3 and it creates black squares due to the fact the array is not in a 640x480x3 format can this be worked around to get the colored bar image?.
f(:,:,1)=[255;0;0;0;0];
f(:,:,2)=[0;255;0;0;255];
f(:,:,3)=[0;0;255;0;2];
num_of_colors=numel(f(:,:,1));
img_resize_height=640
img_resize_height_tmp=round(img_resize_height/num_of_colors); %create the height wanted
%1) create size of array wanted
[r_im_tmp_x r_im_tmp_y]=meshgrid((f(:,:,1)),1:img_resize_height_tmp)
[g_im_tmp_x g_im_tmp_y]=meshgrid((f(:,:,2)),1:img_resize_height_tmp);
[b_im_tmp_x b_im_tmp_y]=meshgrid((f(:,:,3)),1:img_resize_height_tmp);
%2) reshape grid to evenly space out colors (in one column)
r_resize_tmp=reshape(r_im_tmp_x,[1,numel(r_im_tmp_x)])';
g_resize_tmp=reshape(g_im_tmp_x,[1,numel(g_im_tmp_x)])';
b_resize_tmp=reshape(b_im_tmp_x,[1,numel(b_im_tmp_x)])';
%3 make array size wanted 480
img_resize_len=480;
r_resize_tmp2=repmat(r_resize_tmp,([1,img_resize_len]));
g_resize_tmp2=repmat(g_resize_tmp,([1,img_resize_len]));
b_resize_tmp2=repmat(b_resize_tmp,([1,img_resize_len]));
img_resize_rgb(:,:,1)=r_resize_tmp2;
img_resize_rgb(:,:,2)=g_resize_tmp2;
img_resize_rgb(:,:,3)=b_resize_tmp2;
figure(1);
imshow(img_resize_rgb);
The image it creates is correct there just seems like there may be a simpler / better way to code this.
I tried using imresize command to do the same thing to improve the code. (see code below).
pkg load image
f(:,:,1)=[255;0;0;0;0];
f(:,:,2)=[0;255;0;0;255];
f(:,:,3)=[0;0;255;0;2];
height_wanted=640;
width_wanted=480;
repmat_rgb=cat(2,f,f); %add another column to array to get imresize to work
reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'nearest'); %reshape swatch to large output
imshow(reshaped_output);
The image created is incorrect and black and white (most likely due to the array being 640x480 instead of 640x480x3 (how can I fix this?)
It looks like a bug in imresize implementation of Octave image package (in MATLAB the code is working).
When the input of imresize is RGB (3D matrix), the output should also be RGB (3D matrix).
In your example the output is Grayscale (2D matrix instead of 3D matrix).
It is a bug in imresize implementation!
The function is "open source", and we can debug it using the debugger.
Executing the code step by step (stepping into imresize) get us to the following piece of code:
elseif (strcmpi (method, "nearest") && all ([int_row_scale int_col_scale]))
## we are matlab incompatible here on purpose. We can the stuff here in 2
## ways. With interp2 or by clever indexing. Indexing is much much faster
## than interp2 but they return different results (the way we are doing it
## at least). Matlab does the same as we are doing if the both columns and
## rows go the same direction but if they increase one and decrease the
## other, then they return the same as if we were using interp2. We are
## smarter and use indexing even in that case but then the results differ
if (int_row_scale == 1)
row_idx = (1:rows (im))(ones (1, scale_rows), :);
elseif (int_row_scale == -1)
row_idx = ceil (linspace (floor (1/(scale_rows * 2)) + 1, inRows, outRows));
endif
if (int_col_scale == 1)
col_idx = (1:columns (im))(ones (scale_cols, 1), :);
elseif (int_col_scale == -1)
col_idx = ceil (linspace (floor (1/(scale_cols * 2)) + 1, inCols, outCols));
endif
im = im(row_idx, col_idx);
The bug is in the last line of the above part.
Instead of im = im(row_idx, col_idx); it should be:
im = im(row_idx, col_idx, :);
In case you don't want to edit the "image package" code, you may use the following workaround:
Resize each color channel and concatenate the resized channels.
Replace reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted], 'nearest'); with:
out_r = imresize(repmat_rgb(:, :, 1), [height_wanted, width_wanted], 'nearest');
out_g = imresize(repmat_rgb(:, :, 2), [height_wanted, width_wanted], 'nearest');
out_b = imresize(repmat_rgb(:, :, 3), [height_wanted, width_wanted], 'nearest');
reshaped_output = cat(3, out_r, out_g, out_b);
Note:
The class of f is double, and the range of the values supposed to be [0, 1].
All values above 1 are clipped to 1 when using imshow.
You may initialize f to:
f(:,:,1)=[1;0;0;0;0];
f(:,:,2)=[0;1;0;0;1];
f(:,:,3)=[0;0;1;0;1];
Or cast to uint8:
f(:,:,1)=[255;0;0;0;0];
f(:,:,2)=[0;255;0;0;255];
f(:,:,3)=[0;0;255;0;255];
f = uint8(f);
Background:
I am programming SIFT in matlab. I have computed the Difference of Gaussians and have stored them in a 2D cell array. The images in column 2 are half the size of column 1 and so on.
Questions.
Now that I have all of the images stored in my 2D cell array I would like to print them all in one figure.
Im been browsing the web for quite a bit but I haven't seen anything that could help. If anyone could point me in the right direction or provide an example it would be greatly appriciated.
Cheers
If you want a really simple solution then just make a composite image and fill in the regions with the images in the gaussian pyramid. I've given an example code below the works for my case but needs to be adapted for yours.
Code:
% Get total width and height
width_total = 0;
height_total = 0;
for i = 0:3 % Cycle over scales - 4 total
width_total = width_total+size(obj.gaussianpyramid{i+1,1},2);
height_total = height_total+size(obj.gaussianpyramid{i+1,1},1);
end
% Form composite gaussian
compositegaussian = zeros(width_total,height_total);
ind_x = 0;
for i = 0:3 % Cycle over octaves - 4 total
for j = 0:4 % Cycle over scales - 5 total
ind_y = j*size(obj.gaussianpyramid{i+1,j+1},1);
compositegaussian(ind_y+1:ind_y+size(obj.gaussianpyramid{i+1,j+1},1),ind_x+1:ind_x+size(obj.gaussianpyramid{i+1,j+1},2)) = obj.gaussianpyramid{i+1,j+1};
end
ind_x = ind_x + size(obj.gaussianpyramid{i+1,1},2);
end
figure, imshow(compositegaussian,[]);
Output:
Lets generate random 5x2 cell array where the first columns contains 10x10 images and the second - 5x5 images:
c = cell(5,2);
for k=1:5
c{k,1} = uint8(255 * rand(10));
c{k,2} = uint8(255 * rand(5));
end
The following code illustrates them:
figure;
n = size(c, 1);
for k = 1 : n
subplot(n, 2, k * 2 - 1);
image(c{k,1});
subplot(n, 2, k * 2);
image(c{k,2});
end
If the images are upside down, use set(gca,'YDir','normal'); after each image() call.
Hi would it be possible to text or label to an Shape object in silverlight like an arc? Currently I created a chart compose of multiple arcs, I need to set a label on top of the arc to identify whose data it is.
You can use a PathListBox if you want to place the text on an arc. See text along curvature path like circular or arc in silverlight
Alternatively, you can position your own TextBlock object. Use the Polar to Rectangular conversion http://www.teacherschoice.com.au/maths_library/coordinates/polar_-_rectangular_conversion.htm
For instance if the center of your circle is 10,20 and the radius is 30 and the angle where you want to place the textblock is 45, then
double DegreeToRadian(double degree) { return Math.PI / 180 * degree; }
x = 30 * Math.Cos(DegreeToRadian(45)) + 10
y = 30 * Math.Sin(DegreeToRadian(45)) + 20
I'm writing a opengl program that use freetype2 as text rendering engine.
Using its LCD subpixel rendering, I found that there are always some noise pixels in the rendered result, why is that happening? Besides, although it's manual says that the LCD mode will generate buffer with width a multiple of 3, I often found the width to be 3n+1 or 3n+2, and inconsistent with the face->glyph->bitmap->width.
Actually, after hours of trying and testing, I realized that the rasterized glyph data has some non-relevant bytes called padding. Illustratively, imaging below is a glyph data in a buffer: (o/x are meaningful data, while . are non-relevant)
0 1 2 3 4 5 6 7
0 o x o x o x . .
1 x o x o x o . .
2 o x o x o x . .
3 x o x o x o . .
4 o x o x o x . .
There are three numbers describing the size of this buffer, the first two are obvious:
rows = 5 //since there are 5 rows
width = 6 //since each row has 6 bytes of data
However, there is actually a third one:
pitch = 8 //the actual width of rows, including "padding"
If you ignore this property of buffer like me, and got the wrong idea that the width is the actual width, you'll be rendering a distorted or translated glyph shape.
My understanding of this 'padding' is like Dhaivat Pandya has said, it's a compensation. However, it's not a compensation for parity, (obviously +2 is not changing parity,) by default it's a compensation to make the actual width a multiple of 4. But yes, you can change the 4 into 2 or even 1. I guess by forming a data matrix with its width a multiple of 4, it can be loaded faster, for example, to be loaded in longint instead of byte.
But still, the insightfulness of R.. really impressed me. I think you guys just can't image I could make such a basic mistake.
I've never used FreeType library, so I can't talk by personal experience, but maybe that "noise" is because your text width or your calculation of the top-left text coordinate is off by one?
In VBA for PowerPoint, as far as I understand, this code gets only the first shape in the active window and nudges it:
Set oShape = oSlide.Shapes(1)
oShape.Left = oShape.Left + 5
And if I wanted to nudge all the shapes, I would use a loop for this.
But how can I get and nudge only certain shapes, based on their number?
For example, let's say I have only 3 shapes in the active window. What if I want to nudge shape 1 and shape 3, but I don't want to touch shape 2. How could I do that?
If you want to specify specific shapes by number, use something like this:
For Each shapeNum In Array(1, 3, 5, 9, 10)
Set oShape = oSlide.Shapes(shapeNum)
oShape.Left = oShape.Left + 5
Next shapeNum
If you just want to randomly move certain shapes, then use this:
For shapeNum = 1 To oSlide.Shapes.Count
If Rnd < 0.5 Then ''1 in 2 chance
Set oShape = oSlide.Shapes(shapeNum)
oShape.Left = oShape.Left + 5
End If
Next shapeNum
If you wanted something else, add the detail to your question.