herrDeng網內搜尋

自訂搜尋

Ads

2017年12月13日 星期三

ex11 C++/CLI Bitmap圓圖旋轉




//產生圓圖的函數
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");
} 

32 則留言:

b10533006 劉純賓 提到...


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");
}

b10533007 魏辰熾 提到...

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");
}

b10533008 張士晟 提到...

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");
}

b10533009 張仲崴 提到...

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");
}

b10533011 江道逸 提到...

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");
}

b10533018 陳郁傑 提到...

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");
}

b10533062 洪尚郁 提到...

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");
}

B10433065劉勝威 提到...

//將圓圖旋轉
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));
}

B10533010蕭凱維 提到...

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");
}

B10533132許敏茹 提到...

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");
}

B10533004李登恩 提到...

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");
}

B10433065劉勝威 提到...

//將圓圖旋轉
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));
}

B10433072廖翊翔 提到...

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");
}

B10433081巫明芬 提到...

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");
}

b10333093徐子軒 提到...

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");
}

B10433073何明宗 提到...

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");
}

B10433090蔡語鋐 提到...

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");
}

B10433106簡瑋佑 提到...

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");
}

B10433094簡筱芸 提到...

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");
}

b10433107 袁婕寧 提到...

#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;
}

b10433071 雷昕翰 提到...

#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;
}

B10537208楊蕊筑 提到...

#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;
}

B10533088葉俊江 提到...

#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;
}

B10533083徐士興 提到...

#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;
}

B10533071徐琮淇 提到...

#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;
}

b10533075 陳詔瑋 提到...

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");
}

b10533029 游淑娥 提到...

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");
}

B10433088 葉凱文 提到...

#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;
}

b1053073黃叡哲 提到...

#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;
}

B10533076姜國傑 提到...

#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;
}

B10533093許永炎 提到...

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");
}

b10533085羅偉辰 提到...

#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;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章