การใส่ลายน้ำให้รูปพร้อมๆกันเยอะๆ 

การใส่ลายน้ำให้รูปพร้อมๆกันเยอะๆ



ลายน้ำหรือ watermark คือ ไอ้คำว่า expert-programming-tutor.com ในรูปนี้




เคยเป็นไหม อยากจะใส่ลายน้ำ ให้รูปพร้อมๆกันหลายๆ รูป แบบไม่ต้องมานั่งทำด้วยมือที่ละ file
บางคนอาจจะขยัยแต่สำหรับคนขี้เกียจอย่างผมผมจึงเขียน code ขึ้นมาให้คอมพิวเตอร์ช่วยทำ

จึงขออธิบายวิธีการเป็น step แบบนี้
1 list รูปทุกรูปใน folder ที่เราต้องการ ก่อน



private void button1_Click(object sender, EventArgs e)
{
ProcessDirectory("D:\\JAVA_งานน้องตี้\\HTMLPad\\img");
}


public void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);

// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}



โดยใน code นี้จะเป็นการ recursive ไปตาม folder ต่างๆที่เป็น folder ลูกของ folder ตั้งต้นของเรา

แล้ว เรียก function ProcessFile

2 step ที่สอง คือ




public static void ProcessFile(string path)
{
Console.WriteLine("Processed file '{0}'.", path);
Bitmap bmp = (Bitmap)(Bitmap.FromFile(path));
Graphics gg = Graphics.FromImage(bmp);

gg.TranslateTransform(20, 20);
gg.RotateTransform((float)( 180.0 / Math.PI * Math.Atan2(bmp.Height , bmp.Width ) ));

SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 255));
gg.CompositingQuality = CompositingQuality.GammaCorrected;
gg.DrawString("expert-programming-tutor.com Tel. 0853507540", new Font("Ariel", 25, FontStyle.Regular), semiTransBrush, 0, 0);


gg.Flush();

String path2 = path.Replace("D:\\JAVA_งานน้องตี้\\HTMLPad\\img\\", "D:\\JAVA_งานน้องตี้\\HTMLPad\\img2\\") ;
if (! Directory .Exists ( Path.GetDirectoryName (path2 ) ))
{
Directory.CreateDirectory(Path.GetDirectoryName(path2));
}
bmp.Save(path2, System.Drawing.Imaging.ImageFormat.Jpeg);
}



สร้าง Graphics จาก Bitmap
translate
rotate
ไปยังตำแหน่งที่ต้องการ

พิมพ์ข้อความที่ต้องการลงไป

save รูปไปยัง path ใหม่ที่ต้องการ


ความรู้ที่ใช้สำหรับเรื่องนี้ (การใส่ watermark แบบ อัตโนมัต)
1 LOOP
2 recursive
3 Array
4 Graphics
5 การ search google หาวิธีใช้ transparent
6 การ translate และ การ rotate รูป



[ view entry ] ( 1158 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3.1 / 1711 )
การดึงข้อมูลหุ้น จาก www.set.co.th แบบ อัตโนมันติ โดยใช้ C# 

การดึงข้อมูลหุ้น จาก www.set.co.th แบบ อัตโนมันติ โดยใช้ C#




เนื่องจาก คุณช้วงต้องการ code ตัวอย่าง การดึงข้อมูล หุ้นแบบ อัตโนมัต โดยใช้ C# ให้สามารถ ดึงได้ที่ละ หลายๆ หุ้นพร้อมๆ กัน ดังนั้น ผมจึงเขียนให้ สามารถ download ได้ที่

[ถ้าอยากได้ส่ง mail มาขอที่ ntprintf@gmail.com ]

ซึ่งในการนี้ เราใช้ HtmlAgilityPack เป็นตัวช่วยในกา parse XML ครับ
และใช้ HttpWebRequest ในการดึงข้อมูลครับ

ตัวอย่าง หน้าจอ







โดยสามารถ ใส่ตัวย่อหุ้น และ load ได้อย่างอัตโนมัติ ครับ
เราชื่อว่า ถ้าเรียน CS 102 แบบ มาเรียนอย่างต่อเนื่อง และ ทำการบ้านมาส่งทุกครั้งน่าจะ ทำ แนวๆนี้ได้

[ view entry ] ( 1299 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 2.9 / 1781 )
เขียนโปรแกรมจับตา โดยใช้ OPENCV 

เขียนโปรแกรมจับตา โดยใช้ OPENCV



link น่าสนใจ

http://www.youtube.com/watch?v=LHfUeyxhgvk

http://www.youtube.com/watch?v=JL3Gbb9aY0c


https://opencv-code.com/tutorials/eye-detection-and-tracking/


http://hackaday.com/2012/05/30/opencv-k ... -tracking/


[ view entry ] ( 2825 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2505 )
การใช้ high Resolution Timer ด้วย c++ 


การใช้ high Resolution Timer ด้วย c++




#include <windows.h>
#include <stdio.h>
#include <conio.h>

typedef struct {
LARGE_INTEGER start;
LARGE_INTEGER stop;
} stopWatch;

class CStopWatch {

private:
stopWatch timer;
LARGE_INTEGER frequency;
double LIToSecs( LARGE_INTEGER & L) ;
public:
CStopWatch() ;
void startTimer( ) ;
void stopTimer( ) ;
double getElapsedTime() ;
};
double CStopWatch::LIToSecs( LARGE_INTEGER & L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ;
}

CStopWatch::CStopWatch(){
timer.start.QuadPart=0;
timer.stop.QuadPart=0;
QueryPerformanceFrequency( &frequency ) ;
}

void CStopWatch::startTimer( ) {
QueryPerformanceCounter(&timer.start) ;
}

void CStopWatch::stopTimer( ) {
QueryPerformanceCounter(&timer.stop) ;
}

double CStopWatch::getElapsedTime() {
LARGE_INTEGER time;
time.QuadPart = timer.stop.QuadPart - timer.start.QuadPart;
return LIToSecs( time) ;
}

#define n 200000

int main(int argc, char*argv[])
{
int x[n];
int j= 0;
int k = 1;
int l = 0;
int m=0;
CStopWatch timer;
for(int k=1;k<n/2;k=k*2)
{
timer.startTimer();
for(int l=0;l<20;l++)
{

for(int i=0;i< k;i++)
{
m=i;
while(m<n)
{
//printf("%d ",m);
x[m] = 7*x[m]*x[m];
m = (m + k ) ;
}
}
}
timer.stopTimer();
printf("\nk= %d --> \t%lf\n\n",k,timer.getElapsedTime());
}



}



http://expert-programming-tutor.com/

[ view entry ] ( 2815 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2467 )
เฉลย Google Code jam 2009 : Welcome to google code jam (Dynamic Programming) 


เฉลย Google Code jam 2009 : Welcome to google code jam (Dynamic Programming)




จากโจทย์
https://code.google.com/codejam/contest/90101/dashboard#s=p2&a=2


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;

public class WelcomToGoogleCodeJam {
public static void main(String[] args) {
try {
String welcom = "welcome to code jam";
PrintWriter pw = new PrintWriter(new File("out-large.out"));
Scanner sc = new Scanner(new File("C-large-practice.in"));

int T = Integer.parseInt(sc.nextLine());
for (int i = 1; i <= T; i++) {
String s = sc.nextLine();
BigInteger mem[] = new BigInteger[welcom.length()];
for(int j=0;j< welcom.length();j++)
{
mem[j] = new BigInteger("0");
}
for (int j = 0; j < s.length(); j++) {
char x = s.charAt(j);
if (welcom.contains("" + x)) {
if (x == welcom.charAt(0)) {
mem[0] = mem[0] .add(BigInteger.ONE);
} else {
for (int k = 1; k < welcom.length(); k++) {
if (x == welcom.charAt(k))
mem[k] = mem[k].add( mem[k - 1]);
}
}
}
}
String output ;
output = String.format("%04d", mem[ welcom.length()-1].mod(new BigInteger( "10000")));
System.out.println("Case #"+i+": "+output);
pw.println("Case #"+i+": "+output);
}
pw.close();
} catch (IOException ee) {
ee.printStackTrace();
}

}
}



[ view entry ] ( 1254 views )   |  permalink  |  $star_image$star_image$star_image$star_image$star_image ( 3 / 422 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | Next> Last>>