//產生圓圖的函數 void toDisk(Bitmap^ im) { int W = im->Width, H = im->Height; if (W!=H) { cout<<"W!=H\n"; return; } Bitmap im2(W, H); double s, t, c = (W -1)/ 2.0 , r=W/2.0; Color Black = Color::FromArgb(0, 0, 0); for (int x = 0; x < W; x++) { s = x - c; for (int y = 0; y < H; y++){ Color pixel = im->GetPixel(x, y); t = y - c; if (s*s + t*t > r*r) pixel = Black; im2.SetPixel(x, y, pixel); } } im2.MakeTransparent(Black); im2.Save("disk.png"); }
herrDeng網內搜尋
自訂搜尋
Ads
2017年12月13日 星期三
ex11 C++/CLI Bitmap圓圖旋轉
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
你會用C的算子sizeof?
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
-
C++ DP動態規劃解Leetcode 937 Maximum Number of Points with Cost 有些標示medium要比標示hard的問題還要難,Leetcode 1937. Maximum Number of Points with Cost,DP動態規...
32 則留言:
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
void to_rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
t = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t + t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
//將圓圖旋轉
void rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
//宣告整數值W、H,將圖片的寬跟長傳到W、H
//宣告浮點數 S、T、C(圓心)、R(半徑)
Bitmap im2(W, H); //宣告物件 im2 (W=寬,H=長)
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
//常數 const double PI 不可變
const double PI = 3.1415926535897932384626433832795;
//
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
//
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
//
int xOld = (int)round(s*cos_t - t*sin_t + c);
xOld = Clamp(xOld, 0, W - 1);
int yOld = (int)round(s*sin_t + t*cos_t + c);
yOld = Clamp(yOld, 0, H - 1);
Color pixel = im->GetPixel(xOld, yOld);
//畫圓圈之外變成黑色
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
//將黑色部分去背
im2.MakeTransparent(Black);
//存為 "Rotate+度數.png"
//im2.Save("Rotate"+angle+"度.png");
//字串串流作法
stringstream ss;
ss << "Rotate" << angle << "度.png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^im, int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = w / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle* PI / 180;
double sin_(theat), cos_t = cos(theta);
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, w - 1);
yPrime = Clamp(yPrime, 0, w - 1);
Color pixel = im->Getpixel(xprime, yprime);
if (s*s + t*t > r*r) pixel = Black;
im2.setpixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.save("rotate.png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FormArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t - t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
//將圓圖旋轉
void rotate(Bitmap^ im,double angle) {
int W = im->Width, H = im->Height;
//宣告整數值W、H,將圖片的寬跟長傳到W、H
//宣告浮點數 S、T、C(圓心)、R(半徑)
Bitmap im2(W, H); //宣告物件 im2 (W=寬,H=長)
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
//常數 const double PI 不可變
const double PI = 3.1415926535897932384626433832795;
//
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
//
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
//
int xOld = (int)round(s*cos_t - t*sin_t + c);
xOld = Clamp(xOld, 0, W - 1);
int yOld = (int)round(s*sin_t + t*cos_t + c);
yOld = Clamp(yOld, 0, H - 1);
Color pixel = im->GetPixel(xOld, yOld);
//畫圓圈之外變成黑色
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
//將黑色部分去背
im2.MakeTransparent(Black);
//存為 "Rotate+度數.png"
//im2.Save("Rotate"+angle+"度.png");
//字串串流作法
stringstream ss;
ss << "Rotate" << angle << "度.png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*cos_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate"+angle+".png");
}
#include <iostream>
#include <cstdlib>
#include <cmath>
#include<sstream>
using namespace std;
#using <System.Drawing.dll>
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<<angle<<".png";
char ff[200];
ss >> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
void rotate(Bitmap^ im, double angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)(round(s*cos_t - t*sin_t + c));
int yPrime = (int)(round(s*sin_t + t*sin_t + c));
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(xPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r)pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate" + angle + ".png");
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
void toDisk(Bitmap^ im) {
int W = im->Width, H = im->Height;
if (W != H) {
cout << "W!=H\n";
return;
}
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
Color pixel = im->GetPixel(x, y);
t = y - c;
if (s*s + t*t > r*r)
pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("disk.png");
}
int Clamp(int x, int L, int U) {
if (x < L)return L;
else if (x > U)return U;
else return x;
}
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle*PI / 180;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++)
{
t = y - c;
int xPrime = (int)round(s*cos_t - t*sin_t + c);
int yPrime = (int)round(s*sin_t + t*cos_t + c);
xPrime = Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if( s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
im2.Save("rotate.png");
}
#include
#include
#include
#include
using namespace std;
#using
using namespace System::Drawing;
void rotate(Bitmap^ im,int angle) {
int W = im->Width, H = im->Height;
Bitmap im2(W, H);
double s, t, c = (W - 1) / 2.0, r = W / 2.0;
const double PI = 3.1415926535897932384626433832795;
double theta = angle / 180.0*PI;
double sin_t = sin(theta), cos_t = cos(theta);
Color Black = Color::FromArgb(0, 0, 0);
for (int x = 0; x < W; x++) {
s = x - c;
for (int y = 0; y < H; y++) {
t = y - c;
int xPrime = (int)round(s* cos_t - t*sin_t + c);
int yPrime = (int)round(s* sin_t + t*cos_t + c);
xPrime=Clamp(xPrime, 0, W - 1);
yPrime = Clamp(yPrime, 0, W - 1);
Color pixel = im->GetPixel(xPrime, yPrime);
if (s*s + t*t > r*r) pixel = Black;
im2.SetPixel(x, y, pixel);
}
}
im2.MakeTransparent(Black);
stringstream ss;
ss<<"rotate"<> ff;
im2.Save(gcnew System::String(ff));
}
int main()
{
Bitmap^ im = gcnew Bitmap("2.jpg");
double angle;
cout << "旋轉角度:";
cin >> angle;
angle = fmod(angle, 360);
rotate(im, angle);
cout << "圖檔練習。\n";
system("Pause");
return 0;
}
張貼留言