Menu

Showing posts with label save. Show all posts
Showing posts with label save. Show all posts

Monday, October 21, 2013

[C#] วิธีการเขียนไฟล์ข้อความ
[C#] How to Write Text File

ขั้นแรก เพิ่มประโยค using ตามด้านล่าง
First, add using statement
  1. using System.IO.StreamWriter;

ขั้นที่สอง ประกาศและนิยามออบเจ็ค StreamWriter ใหม่ เพื่อเขียนไฟล์ข้อความไปที่ file_path
Second, declare and define new StreamWriter object to write text file at file_path
  1. StreamWriter file = new StreamWriter(file_path);

Tuesday, June 18, 2013

[AS3] วิธีการบันทึกภาพ โดยไม่แสดงไฟล์ไดอะล็อก
[AS3] How to Save an Image without File Dialog

ถ้าใช้ Adobe Flash Player ไม่สามารถทำได้
If Adobe Flash Player is used, it is impossible.

อย่างไรก็ตาม มันสามารถที่จะทำได้สำหรับ Adobe Air Player
However, it is possible for Adobe Air Player

สมมติว่า imgByteData เป็นตัวแปรประเภท ByteArray ของภาพ PNG ที่จะบันทึก
Assume that imgByteData is ByteArray of PNG image which will be saved
  1. import flash.filesystem.*;
  2. ...
  3. var fs:FileStream=new FileStream();
  4. fs.open(new File("C:/img.png"), FileMode.WRITE);
  5. fs.writeBytes(imgByteData);
  6. fs.close();

[AS3] วิธีการบันทึกสกรีนเป็นภาพ
[AS3] How to Save Screen to an Image

ขั้นแรกอ่านข้อมูลบิทแมพจากสกรีน
First, get bitmap data from screen
  1. import flash.display.*;
  2. import flash.utils.ByteArray;
  3. ...
  4. var bitmapData:BitmapData = new BitmapData(this.width, this.height);
  5. bitmapData.draw(this);

ถัดมาทำการเข้ารหัสข้อมูลบิทแมพด้วยตัวเข้ารหัสภาพ
Next, encode bitmap data with image encoder

Saturday, June 8, 2013

[OpenCV] วิธีการบันทึกไฟล์วิดีโอ
[OpenCV] How to Write/Save Video File

ขั้นแรก นิยามตัวแปรที่ใช้เขียนไฟล์วิดีโอตามด้านล่างนี้
First, define the video writer as follow
CvVideoWriter* writer = cvCreateVideoWriter(filepath,fourccfpsframe_size, iscolor);

โดยที่
filepath เป็นที่อยู่ของวิดีโอที่ต้องการจะบันทึก ในที่นี้ใช้นามสกุล avi
fourcc เป็น codec ของวิดีโอที่จะบันทึก ในที่นี้ใช้ CV_FOURCC('M','J','P','G') 
where
filepath is the path of output video file, in this case, file extension is avi
fourcc is the codec of video, in this case, CV_FOURCC('M','J','P','G') is used

ขั้นที่สอง เขียนเฟรมแต่ละเฟรมไปยังวิดีโอที่บันทึก
Second, write frame to output video as follow
cvWriteFrame(writer, frame);

ขั้นสุดท้าย ปลดปล่อยหน่วยความจำสำหรับตัวแปรที่ใช้เขียนไฟล์วิดีโอ
Last, release the video writer 
cvReleaseVideoWriter(&writer);