Hello gents.
I have an application under development and I need to rotate an image for an angle of -40 to 40 dgs. I found something on the web,but it is too difficult at this time for me...
http://www.codeguru.com/cpp/g-m/bitmap/imagemanipulation/article.php/c10677/
All I need is a rotated bitmap with dimensions of 250x250pix,same as source.
I don't need the corners,because it is actually rounded bitmap with black corners.
All I need is a void function,which rotates source bitmap to destination one.
I attached also my image,which I want to rotate.
Can anybody help me with this please?
The easiest, simplest and fastest method is to use a drawing program on the PC to create a series of bitmap images already rotated to the desired angle.
Do you really need all 81 images, 1 degree apart, or will a 5 degree increment suffice? Your call, the fewer the simpler.
Store the images in the resource file and draw them to the screen when required.
In this case IDB_BITMAP1 will be the resource ID of the image you require.
If you arrange for all the resource ID's to be consecutive values they can be selected using (IDB_BASE + offset_integer_variable)
To draw it at position x,y
Code:
HBITMAP hbitmap;
hdc=GetDC(hWnd);
hdcMem=CreateCompatibleDC(hdc);
hbitmap=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
SelectObject(hdcMem,hbitmap);
BitBlt(hdc,x,y,250,250,hdcMem,0,0,SRCCOPY);
DeleteDC(hdcMem);
ReleaseDC(hWnd,hdc);
To rotate the image by code can be done, but as you say the code gets pretty complicated and also has a hit on program performance.
Sometimes less is more.
Just a bit late,but after all.
This method I am using normally,but it limits my needs.
The resource image I do need 250x250 pix, X162 in my app)2 rotating images) that means image with dimensions of 2500x4250,that is too much even for Snapdragons and it simply doesn't load that. Therefore I was forced to reduce base resolution to 125x125,but some people reports also problems.
Check out this thread:
http://forum.xda-developers.com/showthread.php?t=682330
Another approach, but it still needs a bit of work and won't look quite as good, (although the more work you put into it, the better it will look), is to draw the image using the GDI drawing functions, in effect turning it into a vector image. Each change in angle would clear the area, then redraw the image. It does not need any memory or resources, merely CPU power to draw it, but GDI drawing is extremely fast.
Another advantage of this method is that it can be scaled to any image size.
The start/end points of lines, central points of circles etc. of each shape can then be rotated round the centre of the image by the angle required, using:
x'= x*Cos(θ)-y*Sin(θ)
y'= x*Sin(θ)+y*Cos(θ)
Where x and y are the distances relative to the centre of the image. Remember that θ is in radians.
In a normal x,y coordinate system (x,y math function graphs etc.) positive values of θ will result in an anticlockwise rotation. In the screen coordinate system 0,0 is the top left of the screen not the bottom left. Y coordinates are in effect inverted, so positive values of θ will result in a clockwise rotation.
You won't be able to use rectangles, as RECT structures and methods that operate on them, only work with horizontally and vertically aligned blocks. You would have to use polygons instead. If you are calculating the next position based on the previous position, as shown in the code below, the values must be held as double, and converted to integer points before drawing them, or the progressive rounding down, will result in the image being drawn progressively smaller. An interesting effect, but not quite what you really want.
To prove this works have a look at the attached, an example of rotating a square.....
Code:
double ptsx[4],ptsy[4];
double st,ct;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
ptsx[0]=ptsy[0]=ptsy[1]=ptsx[3]=50;
ptsx[1]=ptsx[2]=ptsy[2]=ptsy[3]=-50;
st=sin(0.1);
ct=cos(0.1);
GetWindowRect(hWnd, &rt);
GetWindowRect(g_hWndMenuBar,&rtMenu);
mx=(rt.right-rt.left)/2;
my=(rtMenu.top-rt.top)/2;
SelectObject(hdc,GetStockObject(BLACK_PEN));
for(j=0;j<4;j++)
{
MoveToEx(hdc,mx+(int)ptsx[0],my+(int)ptsy[0],NULL);
LineTo(hdc,mx+(int)ptsx[1],my+(int)ptsy[1]);
LineTo(hdc,mx+(int)ptsx[2],my+(int)ptsy[2]);
LineTo(hdc,mx+(int)ptsx[3],my+(int)ptsy[3]);
LineTo(hdc,mx+(int)ptsx[0],my+(int)ptsy[0]);
for(i=0;i<4;i++)
{
x=ptsx[i]*ct - ptsy[i]*st;
y=ptsx[i]*st + ptsy[i]*ct;
ptsx[i]=x;
ptsy[i]=y;
}
}
EndPaint(hWnd, &ps);
break;
Good afternoon ,
I am doing a college project and not make vb.net 2008 logo for mobile devices , the button is transparent
I could put the image transparent by changing the color pink . png
and everything looks good ,
the question is how I can put it after like a button ?
Thanks in advance .
this is the code I have the picturebox2 is the one with the pink color is . png
Dim g As Graphics
g = Graphics.FromImage(PictureBox1.Image)
Dim Picture As Bitmap
Picture = New Bitmap(PictureBox2.Image)
Dim imgatr As New Drawing.Imaging.ImageAttributes()
Dim colorx As Color = Color.FromArgb(255, 0, 255) 'Transparent color
imgatr.SetColorKey(colorx, colorx)
Me.PictureBox2.Visible = False
Dim Rectangle = New Drawing.Rectangle(70, 90, Picture.Width, Picture.Height) 'destination rectange
g.DrawImage(Picture, Rectangle, 0, 0, Picture.Width, Picture.Height, GraphicsUnit.Pixel, imgatr)
Hi,
What I understand is that you want to add a button with a transparent background to something which I suppose is a form or a User Control, is that correct?
There is no such thing like a transparent background button out of the box in .Net CF.
You can implement a custom control for this. A transparent background control needs to know how to paint whatever is behind it before drawing it owns content to provide the transparency effect. You can implement it but keep in mind that you might need to pass a bitmap with the background to the "transparent" control, or build a mechanism to discover it.
However, It's highly probable that in your use case you don't really need such a complexity. Can you please elaborate why do you need a transparent button? if the background is not dynamic, you can probably just create a bitmap that already include the background and that would be enough.
If you have any doubt just send me a private message. It can be in Spanish BTW.
If all you want is the graphics, some web sites will generate them for you.
One is http://cooltext.com/
You can choose from several different graphics and give your own button text. It will generate a PNG with a transparent backgroup, ready to be used.
I would like to request the ability to apply a locality to a rectangle.
I want to design a widget that is a dual-time-zone analog clock. One hour hand would be for local time, and a second hour hand would be for a specified location. Because hour hands are implemented using rectangles and Advanced Parameters that specify sweep angle and rotation as a function of time, I need to be able to specify the locality of the rectangle separately from the widget so that the Advanced Parameters will use the correct time--that of the rectangle, not of the widget.
If this is not the correct forum for feature requests, please let me know where that is.
Thanks.
Jeff Jansen
jsjansen said:
I would like to request the ability to apply a locality to a rectangle.
I want to design a widget that is a dual-time-zone analog clock. One hour hand would be for local time, and a second hour hand would be for a specified location. Because hour hands are implemented using rectangles and Advanced Parameters that specify sweep angle and rotation as a function of time, I need to be able to specify the locality of the rectangle separately from the widget so that the Advanced Parameters will use the correct time--that of the rectangle, not of the widget.
If this is not the correct forum for feature requests, please let me know where that is.
Thanks.
Jeff Jansen
Click to expand...
Click to collapse
Might I suggest that you use the timezone in the sweep angle/ rotation calculation. If you use local time + timezone offset that should adjust the rectangle correctly. I did something like this to make a clock like xkcd:Now (google, I can't post outside links yet ). The outer edge is fixed and the colored timezones rotate. I tried to incorporate the #DZ# variable but I haven't got this quite working yet.
Please allow the values of the Rotation attribute of widget elements to be decimal values, not just integers.
In many cases, the one-degree increment is simply not precise enough to achieve the desired effect. One example is using a circular Progress Bar to create minute markers for a clock. To do this, I adjust the X Offset, Rotation, Spacing, and Split values so that the minute markers align properly. The problem is, when I get the zero-minute (12 o'clock) marker placed precisely, the 30-minute (6 o'clock) marker is too far to the left of where it should be, and adjusting the Rotation by one degree moves it too far to the right.
Another example is that it is impossible to create a line (width=1 rectangle) that bisects a 45-degree angle, because that requires a rotation of 22.5 degrees.
Thanks for considering this request.
I am trying to create an old school weather center with temperature, Humidity, and Pressure. I can make hands using a progress bar by setting the main and secondary colors clear and setting the gradent to highlight current. I dont like the reverse wedge shape though. What I need are the conditionals for using a rectangle as hands. I need the complete conditionals for a 360 degree sweep for each one, and what to change for different sweeps. Example: I want my humidity to sweep 300 degrees, starting at - 30 degrees. Also. I hear of a way to make bitmap images sweep with progress bar. This may help more as i can use fancy instrument needles for indicators.
Wrong thread