星期三, 11月 07, 2012

use intent to share media to YouTube or Facebook

    private void share_media(String outputFile){
        // first check if the outputFile is exists
        if (!new File(outputFile).isFile()){
            return;
        }
        ContentValues content = new ContentValues(4);
        content.put(Video.VideoColumns.TITLE, "My Test");
        content.put(Video.VideoColumns.DATE_ADDED,
        System.currentTimeMillis() / 1000);
        content.put(Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, outputFile);
        ContentResolver resolver = getContentResolver();
        Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
     
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("video/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        try {
            startActivity(Intent.createChooser(intent, "Share using"));       
        }
        catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(getApplicationContext(),"No way to share",Toast.LENGTH_LONG).show();
        }
        return;
    }

星期二, 11月 06, 2012

Convert Side by Side image to Blue & Red 3D stereo mode

Convert Side by Side image to Blue & Red 3D stereo mode           

Bitmap dst = null;
int w = src_bitmap.getWidth();
int h = src_bitmap.getHeight();
int [] dst_pixs = new int[w * h];
int[] left_pixs;
int[] right_pixs;
int alpha;
int r;
int g;
int b;
// fix if width or height is odd will cause crash
if (w % 2 == 1){
    w = w-1;
}
if (h % 2 == 1){
    h = h-1;
}
//
int totals = w * h;

left_pixs = new int[(w / 2) * h];
right_pixs = new int[(w / 2) * h];
// Get Left and Right Pixs
src.getPixels(left_pixs, 0, w/2, 0, 0, w/2, h);
src.getPixels(right_pixs, 0, w/2, w/2, 0, w/2, h);
//
dst = Bitmap.createBitmap(w, h, Config.ARGB_8888);

for (i = 0; i < totals - 1; i++) {
                // Convert color , For blue & red ==> (left.a, left.r, right.g, right.b)
                alpha = left_pixs[i/2] & 0xff000000;
                r = (left_pixs[i/2] >> 16) & 0xff;
                g = (right_pixs[i/2] >> 8) & 0xff;
                b = right_pixs[i/2] & 0xff;
                dst_pixs[i] = alpha | (r << 16) | (g << 8) | b;
                // end conver color  
 }
dst.setPixels(dst_pixs, 0, w, 0, 0, w, h);