Advertisement
Guest User

PhotoMerzing

a guest
Dec 5th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.29 KB | None | 0 0
  1. public class PhotoMargingActivity extends Activity implements OnClickListener{
  2. /** Called when the activity is first created. */
  3. private Button share,flshControl,buttonClick,capture,mSave;
  4. TextView addText, addTexture, effect_name;
  5. private final String TAG = "CameraDemo";
  6. Bitmap imageBitmap;
  7. String[] effectNames={"Darken","Color Burn","Overlay","Soft Light","Hard Light","Vivid Light","Hue","Pin Light"};
  8. ImageView btnLeft,btnRight;
  9. private EditText mText;
  10. int selectedItem, effectNumber=0;
  11. AlertDialog alert,alert1;
  12. Bitmap bmOut;
  13. boolean Flash = false;
  14. Gallery g;
  15. int i =0;
  16. boolean addtextClicked = true;
  17. String textureEffects[]= {"bright red","broken glass","clouds","cloudy art","cloudy art 2",
  18. "colorful 7","colorful blotches","colorful blotches frame","colorful circles","cyclos","danger","dirty screen 2",
  19. "dirty screen 3","dont look","endless route","fancy m
  20. "swag","verde","x ray blue","yellow wood","warning","golden circle","green","old paper","passion","rays of light","semicircles","","","","","","","","","","","",};
  21. private Integer[] mImageIds = {
  22. R.drawable.dreaming, R.drawable.bluefilm, R.drawable.chromatic_lights, R.drawable.dirty_screen,
  23. R.drawable.colorful_blotches,R.drawable.colorful_blotches_frame,
  24. R.drawable.colorful_circles,R.drawable.cyclos, R.drawable.danger,
  25. R.drawable.oldfilm, R.drawable.oldmusic,
  26.  
  27. };
  28.  
  29. Dialog mDialog;
  30. LinearLayout previewImage;
  31. /// public Camera camera;
  32. public static ImageView img;
  33. private Bitmap mBit;
  34. int ItemsInGallery=0;
  35. int CurrentIndex=0;
  36. Preview preview;
  37. FrameLayout mfram;
  38. public static Bitmap icon;
  39. Typeface tf,tf1,tf2,tf3,tf4,tf5;
  40. @Override
  41. public void onCreate(Bundle savedInstanceState) {
  42. super.onCreate(savedInstanceState);
  43. setContentView(R.layout.main);
  44.  
  45. tf = Typeface.createFromAsset(getAssets(),"fonts/FtraBk_0.ttf");
  46. tf1 = Typeface.createFromAsset(getAssets(),"fonts/DESYREL.ttf");
  47. tf2 = Typeface.createFromAsset(getAssets(),"fonts/Helvetica.ttf");
  48. // tf3 = Typeface.createFromAsset(getAssets(),"TR_Arial.ttf");
  49. tf4 = Typeface.createFromAsset(getAssets(),"fonts/ufonts.com_bradley-hand-itc-2.ttf");
  50. tf5 = Typeface.createFromAsset(getAssets(),"fonts/ufonts.com_cochin1.ttf");
  51. mText=(EditText)findViewById(R.id.text);
  52.  
  53. // image veiw text.............................
  54. img=(ImageView)findViewById(R.id.img);
  55. //...............image id...............................
  56.  
  57. previewImage = (LinearLayout) findViewById(R.id.preview_image);
  58. mfram=(FrameLayout) findViewById(R.id.preview1234);
  59. capture=(Button)findViewById(R.id.capture);
  60. mSave=(Button)findViewById(R.id.save);
  61. addTexture = (TextView) findViewById(R.id.add_texture);
  62.  
  63. //.................. to get the intent from ... main1 class........................
  64.  
  65. Bundle bundle = getIntent().getExtras();
  66. if(bundle.getBoolean("image"))
  67. {
  68.  
  69. //............. here to get the decode file of image.................. main1 class
  70. Bitmap b = Bitmap.createBitmap(Main1.mBitMap);
  71.  
  72. img.setImageBitmap(b);
  73. previewImage.setVisibility(View.GONE);
  74. }else{
  75. //capture.setVisibility(View.VISIBLE);
  76. i++;
  77. preview = new Preview(PhotoMargingActivity.this);
  78. mfram.addView(preview);
  79.  
  80. }
  81. icon = Main1.mBitMap;
  82.  
  83.  
  84. effect_name= (TextView) findViewById(R.id.change_effects);
  85. btnLeft =(ImageView) findViewById(R.id.btn_left);
  86. btnRight = (ImageView) findViewById(R.id.btn_right);
  87.  
  88. btnLeft.setOnClickListener(new OnClickListener() {
  89. @Override
  90. public void onClick(View arg0) {
  91. // TODO Auto-generated method stub
  92. if(effectNumber==0) effectNumber=7;
  93. else effectNumber--;
  94. applyEffect();
  95.  
  96. }
  97. });
  98. btnRight.setOnClickListener(new OnClickListener() {
  99.  
  100. @Override
  101. public void onClick(View arg0) {
  102. // TODO Auto-generated method stub
  103. if(effectNumber==7) effectNumber=0;
  104. else effectNumber++;
  105. applyEffect();
  106.  
  107.  
  108. }
  109. });
  110.  
  111. buttonClick = (Button) findViewById(R.id.btnClick);
  112. buttonClick.setOnClickListener( new OnClickListener() {
  113. public void onClick(View v) {
  114.  
  115. //img.setVisibility(View.GONE);
  116. i++;
  117. if(i == 1){
  118. //capture.setVisibility(View.VISIBLE);
  119. preview = new Preview(PhotoMargingActivity.this);
  120. mfram.addView(preview);
  121.  
  122. }else if(i==2){
  123. preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
  124. }
  125.  
  126.  
  127. }
  128. });
  129.  
  130. flshControl=(Button)findViewById(R.id.flsh_control);
  131. flshControl.setOnClickListener(new OnClickListener() {
  132. @Override
  133. public void onClick(View arg0) {
  134. //createSepiaToningEffect(BitmapFactory.decodeResource(getResources(),R.drawable.antartica1),1,10,10,255);
  135. if(PhotoMargingActivity.this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
  136. //Flash = (Flash == true) ? false : true;
  137. if(!Flash){
  138. Parameters p = preview.camera.getParameters();
  139. p.setFlashMode(Parameters.FLASH_MODE_TORCH);
  140. preview.camera.setParameters(p);
  141. Flash = true;
  142. }else{
  143. Parameters p = preview.camera.getParameters();
  144. p.setFlashMode(Parameters.FLASH_MODE_OFF);
  145. preview.camera.setParameters(p);
  146. Flash = false;
  147. }
  148.  
  149. }
  150. }
  151. });
  152.  
  153.  
  154.  
  155.  
  156.  
  157. capture.setOnClickListener(new OnClickListener() {
  158.  
  159. @Override
  160. public void onClick(View arg0) {
  161. // TODO Auto-generated method stub
  162. preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
  163.  
  164. //mfram.setVisibility(View.GONE);
  165. }
  166. });
  167.  
  168.  
  169. mSave.setOnClickListener(new OnClickListener() {
  170.  
  171. @Override
  172. public void onClick(View arg0) {
  173. File cacheDir;
  174. Bitmap bitmap = icon;
  175.  
  176. // String path = Environment.getExternalStorageDirectory().toString();
  177. OutputStream fOut = null;
  178. Date d=new Date();
  179.  
  180. if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
  181. cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Photo Art Camera");
  182. else
  183. cacheDir=PhotoMargingActivity.this.getCacheDir();
  184. if(!cacheDir.exists())
  185. cacheDir.mkdirs();
  186.  
  187. File file = new File(cacheDir, "PhotoMarge"+d.getTime()+".jpg");
  188. try {
  189. fOut = new FileOutputStream(file);
  190. bitmap.compress(CompressFormat.PNG, 100, fOut);
  191. //getImageBitmap(myurl).compress(Bitmap.CompressFormat.JPEG, 85, fOut);
  192. fOut.flush();
  193. fOut.close();
  194.  
  195. Toast.makeText(PhotoMargingActivity.this, "Photo Saved Sucessfully", 500).show();
  196.  
  197. // mDialog.dismiss();
  198.  
  199. //MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
  200. } catch (FileNotFoundException e) {
  201. // TODO Auto-generated catch block
  202. e.printStackTrace();
  203. } catch (Exception e) {
  204. // TODO Auto-generated catch block
  205. e.printStackTrace();
  206. Toast.makeText(PhotoMargingActivity.this, "Photo Not Saved Sucessfully", 500).show();
  207.  
  208. }
  209.  
  210.  
  211. }
  212. });
  213.  
  214.  
  215.  
  216.  
  217. Log.d(TAG, "onCreate'd");
  218.  
  219. g = (Gallery) findViewById(R.id.Gallery01);
  220. g.setAdapter(new ImageAdapter(this));
  221.  
  222. g.setOnItemClickListener(new OnItemClickListener() {
  223. public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
  224. img.setBackgroundResource(mImageIds[position]);
  225. img.setAlpha(170);
  226. addTexture.setText(textureEffects[position]);
  227. }
  228. });
  229.  
  230. share=(Button)findViewById(R.id.share);
  231. share.setOnClickListener(new OnClickListener() {
  232.  
  233. @Override
  234. public void onClick(View arg0) {
  235.  
  236.  
  237.  
  238. mfram.setDrawingCacheEnabled(true);
  239.  
  240. icon = Bitmap.createBitmap(mfram.getDrawingCache());
  241.  
  242. mfram.setDrawingCacheEnabled(false);
  243.  
  244. mDialog=new Dialog(PhotoMargingActivity.this);
  245.  
  246.  
  247.  
  248.  
  249. mDialog=new Dialog(PhotoMargingActivity.this);
  250. mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  251. mDialog.setContentView(R.layout.dialog2);
  252.  
  253.  
  254.  
  255. mDialog.show();
  256.  
  257.  
  258.  
  259.  
  260.  
  261. }
  262. });
  263.  
  264. // mBtn4=(Button)findViewById(R.id.btn4);
  265. // mBtn4.setOnClickListener(new OnClickListener() {
  266. //
  267. // @Override
  268. // public void onClick(View arg0) {
  269. // doInvert(BitmapFactory.decodeResource(getResources(),R.drawable.antartica1));
  270. // }
  271. // });
  272. //
  273. addText=(TextView)findViewById(R.id.add_text);
  274. addText.setOnClickListener(new OnClickListener() {
  275.  
  276. @Override
  277. public void onClick(View arg0) {
  278. // TODO Auto-generated method stub
  279. if(addtextClicked == true){
  280. addtextClicked = false;
  281. showAddTextDialoge();
  282. addText.setBackgroundResource(R.drawable.done);
  283. }
  284. else{
  285. addtextClicked = true;
  286. addText.setBackgroundResource(R.drawable.addtext);
  287.  
  288. }
  289.  
  290. }
  291.  
  292.  
  293.  
  294. });
  295.  
  296. }
  297.  
  298. void applyEffect(){
  299. //img.buildDrawingCache();
  300. //Bitmap bmap = img.getDrawingCache();
  301. //mfram.setDrawingCacheEnabled(true);
  302. // Bitmap b = ll.getDrawingCache();
  303. mfram.removeView(preview);
  304. previewImage.setVisibility(View.VISIBLE);
  305. Bitmap icon1 = icon;
  306. //effect_name.setText(effectNames[effectNumber]);
  307. switch (effectNumber) {
  308. case 0:
  309. int highlightColor = getResources().getColor(R.color.highlight_color_filter);
  310. PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(highlightColor, PorterDuff.Mode.SRC_ATOP);
  311. img.setColorFilter(colorFilter);
  312.  
  313. break;
  314. case 1:
  315. createSepiaToningEffect(icon1,1,255,0,0);
  316. break;
  317. case 2:
  318. createSepiaToningEffect(icon1,1,0,255,0);
  319.  
  320. break;
  321. case 3:
  322. createSepiaToningEffect(icon1,1,0,0,255);
  323. break;
  324. case 4:
  325. doInvert(icon1);
  326. break;
  327. case 5:
  328. doInvert(icon1);
  329. break;
  330. case 6:
  331. doInvert(icon1);
  332. break;
  333. case 7:
  334. doInvert(icon1);
  335. break;
  336. }
  337.  
  338. }
  339.  
  340.  
  341. public class ImageAdapter extends BaseAdapter {
  342. int mGalleryItemBackground;
  343. private Context mContext;
  344.  
  345.  
  346. public ImageAdapter(Context c) {
  347. mContext = c;
  348. TypedArray a = c.obtainStyledAttributes(R.styleable.GalleryA);
  349. mGalleryItemBackground = a.getResourceId(R.styleable.GalleryA_android_galleryItemBackground, 0);
  350. a.recycle();
  351. }
  352.  
  353. public int getCount() {
  354. ItemsInGallery=mImageIds.length;
  355. return mImageIds.length;
  356. }
  357.  
  358. public Object getItem(int position) {
  359. return position;
  360. }
  361.  
  362. public long getItemId(int position) {
  363. return position;
  364. }
  365.  
  366. public View getView(int position, View convertView, ViewGroup parent) {
  367. ImageView i = new ImageView(mContext);
  368.  
  369. i.setImageResource(mImageIds[position]);
  370. i.setLayoutParams(new Gallery.LayoutParams(100, 100));
  371. i.setScaleType(ImageView.ScaleType.FIT_XY);
  372. i.setBackgroundResource(mGalleryItemBackground);
  373.  
  374. return i;
  375. }
  376. }
  377.  
  378.  
  379.  
  380.  
  381. @Override
  382. public void onClick(View v) {
  383. // TODO Auto-generated method stub
  384.  
  385. switch(v.getId())
  386. {
  387. case R.id.btnNext:
  388. //Increase the index
  389.  
  390. CurrentIndex++;
  391. //if reached the end of the gallery, then start from the first item
  392. if(CurrentIndex>ItemsInGallery-1)
  393. CurrentIndex=ItemsInGallery-1;
  394. //CurrentIndex=0;
  395. g.setSelection(CurrentIndex,true);
  396. //txt.setText(String.valueOf(CurrentIndex));
  397. break;
  398. case R.id.btnPrev:
  399. //Decrease the index
  400. CurrentIndex=CurrentIndex-1;
  401. //If reached the first item, then return to the last item in the gallery
  402. if(CurrentIndex<0)
  403. CurrentIndex=0;
  404. //CurrentIndex=ItemsInGallery-1;
  405. g.setSelection(CurrentIndex,true);
  406. //txt.setText(String.valueOf(CurrentIndex));
  407. break;
  408. }
  409.  
  410. }
  411.  
  412.  
  413. //............................................ errorrrrrrrrrrrrrrrrrrrrrrrr...............
  414.  
  415. public void createSepiaToningEffect(Bitmap src, int depth, double red, double green, double blue) {
  416. // image size
  417. int width = src.getWidth();
  418. int height = src.getHeight();
  419. // create output bitmap
  420. bmOut = Bitmap.createBitmap(width, height, src.getConfig());
  421. // constant grayscale
  422. final double GS_RED = 0.3;
  423. final double GS_GREEN = 0.59;
  424. final double GS_BLUE = 0.11;
  425. // color information
  426. int A, R, G, B;
  427. int pixel;
  428.  
  429. // scan through all pixels
  430. for(int x = 0; x < width; ++x) {
  431. for(int y = 0; y < height; ++y) {
  432. // get pixel color
  433. pixel = src.getPixel(x, y);
  434. // get color on each channel
  435. A = Color.alpha(pixel);
  436. R = Color.red(pixel);
  437. G = Color.green(pixel);
  438. B = Color.blue(pixel);
  439. // apply grayscale sample
  440. B = G = R = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);
  441.  
  442. // apply intensity level for sepid-toning on each channel
  443. R += (depth * red);
  444. if(R > 255) { R = 255; }
  445.  
  446. G += (depth * green);
  447. if(G > 255) { G = 255; }
  448.  
  449. B += (depth * blue);
  450. if(B > 255) { B = 255; }
  451.  
  452. // set new pixel color to output image
  453. bmOut.setPixel(x, y, Color.argb(A, R, G, B));
  454. }
  455. }
  456.  
  457. icon=bmOut;
  458. // return final image
  459. img.setImageBitmap(bmOut);
  460.  
  461. }
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. public static Bitmap doInvert(Bitmap src) {
  469. // create new bitmap with the same settings as source bitmap
  470. Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
  471. // color info
  472. int A, R, G, B;
  473. int pixelColor;
  474. // image size
  475. int height = src.getHeight();
  476. int width = src.getWidth();
  477.  
  478. // scan through every pixel
  479. for (int y = 0; y < height; y++)
  480. {
  481. for (int x = 0; x < width; x++)
  482. {
  483. // get one pixel
  484. pixelColor = src.getPixel(x, y);
  485. // saving alpha channel
  486. A = Color.alpha(pixelColor);
  487. // inverting byte for each R/G/B channel
  488. R = 255 - Color.red(pixelColor);
  489. G = 255 - Color.green(pixelColor);
  490. B = 255 - Color.blue(pixelColor);
  491. // set newly-inverted pixel to output image
  492. bmOut.setPixel(x, y, Color.argb(A, R, G, B));
  493. }
  494. }
  495. img.setImageBitmap(bmOut);
  496. // return final bitmap
  497. return bmOut;
  498. }
  499.  
  500.  
  501.  
  502.  
  503.  
  504. public static Bitmap engrave(Bitmap src) {
  505. ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
  506. convMatrix.setAll(0);
  507. convMatrix.Matrix[0][0] = -2;
  508. convMatrix.Matrix[1][1] = 2;
  509. convMatrix.Factor = 1;
  510. convMatrix.Offset = 95;
  511. return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
  512. }
  513.  
  514.  
  515.  
  516.  
  517. public static Bitmap sharpen(Bitmap src, double weight) {
  518. double[][] SharpConfig = new double[][] {
  519. { 0 , -2 , 0 },
  520. { -2, weight, -2 },
  521. { 0 , -2 , 0 }
  522. };
  523. ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
  524. convMatrix.applyConfig(SharpConfig);
  525. convMatrix.Factor = weight - 8;
  526. return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
  527. }
  528.  
  529.  
  530.  
  531.  
  532.  
  533. public static Bitmap applyMeanRemoval(Bitmap src) {
  534. double[][] MeanRemovalConfig = new double[][] {
  535. { -1 , -1, -1 },
  536. { -1 , 9, -1 },
  537. { -1 , -1, -1 }
  538. };
  539. ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
  540. convMatrix.applyConfig(MeanRemovalConfig);
  541. convMatrix.Factor = 1;
  542. convMatrix.Offset = 0;
  543. return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
  544. }
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561. public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) {
  562. // image size
  563. int width = src.getWidth();
  564. int height = src.getHeight();
  565. // create output bitmap
  566. Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
  567. // color information
  568. int A, R, G, B;
  569. int pixel;
  570.  
  571. // scan through all pixels
  572. for(int x = 0; x < width; ++x) {
  573. for(int y = 0; y < height; ++y) {
  574. // get pixel color
  575. pixel = src.getPixel(x, y);
  576. // apply filtering on each channel R, G, B
  577. A = Color.alpha(pixel);
  578. R = (int)(Color.red(pixel) * red);
  579. G = (int)(Color.green(pixel) * green);
  580. B = (int)(Color.blue(pixel) * blue);
  581. // set new color pixel to output bitmap
  582. bmOut.setPixel(x, y, Color.argb(A, R, G, B));
  583. }
  584. }
  585. img.setImageBitmap(bmOut);
  586. // return final image
  587. return bmOut;
  588. }
  589.  
  590.  
  591.  
  592.  
  593.  
  594. public static Bitmap applyShadingFilter(Bitmap source, int shadingColor) {
  595. // get image size
  596. int width = source.getWidth();
  597. int height = source.getHeight();
  598. int[] pixels = new int[width * height];
  599. // get pixel array from source
  600. source.getPixels(pixels, 0, width, 0, 0, width, height);
  601.  
  602. int index = 0;
  603. // iteration through pixels
  604. for(int y = 0; y < height; ++y) {
  605. for(int x = 0; x < width; ++x) {
  606. // get current index in 2D-matrix
  607. index = y * width + x;
  608. // AND
  609. pixels[index] &= shadingColor;
  610. }
  611. }
  612. // output bitmap
  613. Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  614. bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
  615. img.setImageBitmap(bmOut);
  616. return bmOut;
  617. }
  618.  
  619.  
  620.  
  621.  
  622.  
  623. public static Bitmap applySnowEffect(Bitmap source) {
  624. // get image size
  625. int width = source.getWidth();
  626. int height = source.getHeight();
  627. int[] pixels = new int[width * height];
  628. // get pixel array from source
  629. source.getPixels(pixels, 0, width, 0, 0, width, height);
  630. // random object
  631. Random random = new Random();
  632.  
  633. int R, G, B, index = 0, thresHold = 50;
  634. // iteration through pixels
  635. for(int y = 0; y < height; ++y) {
  636. for(int x = 0; x < width; ++x) {
  637. // get current index in 2D-matrix
  638. index = y * width + x;
  639. // get color
  640. R = Color.red(pixels[index]);
  641. G = Color.green(pixels[index]);
  642. B = Color.blue(pixels[index]);
  643. // generate threshold
  644. thresHold = random.nextInt(0xFF);
  645. if(R > thresHold && G > thresHold && B > thresHold) {
  646. pixels[index] = Color.rgb(0xFF, 0xFF, 0xFF);
  647. }
  648. }
  649. }
  650. // output bitmap
  651. Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
  652. bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
  653.  
  654. img.setImageBitmap(bmOut);
  655. return bmOut;
  656. }
  657.  
  658.  
  659.  
  660.  
  661.  
  662. public static Bitmap applyHueFilter(Bitmap source, int level) {
  663. // get image size
  664. int width = source.getWidth();
  665. int height = source.getHeight();
  666. int[] pixels = new int[width * height];
  667. float[] HSV = new float[3];
  668. // get pixel array from source
  669. source.getPixels(pixels, 0, width, 0, 0, width, height);
  670.  
  671. int index = 0;
  672. // iteration through pixels
  673. for(int y = 0; y < height; ++y) {
  674. for(int x = 0; x < width; ++x) {
  675. // get current index in 2D-matrix
  676. index = y * width + x;
  677. // convert to HSV
  678. Color.colorToHSV(pixels[index], HSV);
  679. // increase Saturation level
  680. HSV[0] *= level;
  681. HSV[0] = (float) Math.max(0.0, Math.min(HSV[0], 360.0));
  682. // take color back
  683. pixels[index] |= Color.HSVToColor(HSV);
  684. }
  685. }
  686. // output bitmap
  687. Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  688. bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
  689.  
  690. img.setImageBitmap(bmOut);
  691. return bmOut;
  692. }
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699. public static Bitmap boost(Bitmap src, int type, float percent) {
  700. int width = src.getWidth();
  701. int height = src.getHeight();
  702. Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
  703.  
  704. int A, R, G, B;
  705. int pixel;
  706.  
  707. for(int x = 0; x < width; ++x) {
  708. for(int y = 0; y < height; ++y) {
  709. pixel = src.getPixel(x, y);
  710. A = Color.alpha(pixel);
  711. R = Color.red(pixel);
  712. G = Color.green(pixel);
  713. B = Color.blue(pixel);
  714. if(type == 1) {
  715. R = (int)(R * (1 + percent));
  716. if(R > 255) R = 255;
  717. }
  718. else if(type == 2) {
  719. G = (int)(G * (1 + percent));
  720. if(G > 255) G = 255;
  721. }
  722. else if(type == 3) {
  723. B = (int)(B * (1 + percent));
  724. if(B > 255) B = 255;
  725. }
  726. bmOut.setPixel(x, y, Color.argb(A, R, G, B));
  727. }
  728. }
  729.  
  730. img.setImageBitmap(bmOut);
  731. return bmOut;
  732. }
  733. ShutterCallback shutterCallback = new ShutterCallback() {
  734. public void onShutter() {
  735. Log.d(TAG, "onShutter'd");
  736. }
  737. };
  738.  
  739. /** Handles data for raw picture */
  740. PictureCallback rawCallback = new PictureCallback() {
  741. public void onPictureTaken(byte[] data, Camera camera) {
  742. Log.d(TAG, "onPictureTaken - raw");
  743. }
  744. };
  745.  
  746. /** Handles data for jpeg picture */
  747. PictureCallback jpegCallback = new PictureCallback() {
  748. public void onPictureTaken(byte[] data, Camera camera) {
  749. //FileOutputStream outStream = null;
  750. try {
  751. // write to local sandbox file system
  752. // outStream = CameraDemo.this.openFileOutput(String.format("%d.jpg", System.currentTimeMillis()), 0);
  753. // Or write to sdcard
  754.  
  755. ByteArrayInputStream imagestream=new ByteArrayInputStream(data);
  756. icon=BitmapFactory.decodeStream(imagestream);
  757.  
  758.  
  759. File pic = null;
  760.  
  761. try {
  762. File root = Environment.getExternalStorageDirectory();
  763. if (root.canWrite()){
  764. pic = new File(root,"signature.png");
  765. FileOutputStream out = new FileOutputStream(pic);
  766. icon.compress(CompressFormat.PNG, 100, out);
  767. out.flush();
  768. out.close();
  769. }
  770. } catch (IOException e) {
  771. Log.e("BROKEN", "Could not write file " + e.getMessage());
  772. }
  773.  
  774.  
  775.  
  776. img.setImageBitmap(icon);
  777. //outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
  778. //outStream.write(data);
  779. //outStream.close();
  780. Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
  781. } finally {
  782. }
  783. Log.d(TAG, "onPictureTaken - jpeg");
  784. }
  785. };
  786.  
  787. void showAddTextDialoge(){
  788. final CharSequence[] digitList = { "Arial", "Baskerville", "Bodoni 72","Bradley Hand","Cochin" };
  789. AlertDialog.Builder alt_bld = new AlertDialog.Builder(PhotoMargingActivity.this);
  790. alt_bld.setIcon(R.drawable.icon);
  791. alt_bld.setTitle("Select one Digit");
  792. selectedItem = -1;
  793. alt_bld.setSingleChoiceItems(digitList , -1,new DialogInterface.OnClickListener() {
  794. public void onClick(DialogInterface dialog, int item) {
  795.  
  796. selectedItem = item;
  797.  
  798. if(digitList[item].equals("Arial")){
  799.  
  800. mText.setTypeface(tf);
  801. }
  802.  
  803. else if(digitList[item].equals("Baskerville")){
  804.  
  805. mText.setTypeface(tf1);
  806. }
  807.  
  808. else if(digitList[item].equals("Bodoni 72")){
  809.  
  810. mText.setTypeface(tf2);
  811. }
  812.  
  813. else if(digitList[item].equals("Bradley Hand")){
  814.  
  815. mText.setTypeface(tf4);
  816. }
  817.  
  818. else if(digitList[item].equals("Cochin")){
  819.  
  820. mText.setTypeface(tf5);
  821. }
  822.  
  823.  
  824. alert.dismiss();
  825.  
  826.  
  827. final CharSequence[] ColorList = { "Red", "Green", "Blue","Orange","White","Gray","Black","Yellow" };
  828. AlertDialog.Builder alt_bld1 = new AlertDialog.Builder(PhotoMargingActivity.this);
  829. alt_bld1.setIcon(R.drawable.icon);
  830. alt_bld1.setTitle("Select one Digit");
  831. selectedItem = -1;
  832. alt_bld1.setSingleChoiceItems(ColorList , -1,new DialogInterface.OnClickListener() {
  833. public void onClick(DialogInterface dialog, int item) {
  834.  
  835. selectedItem = item;
  836. mText.setVisibility(View.VISIBLE);
  837. if(ColorList[item].equals("Red")){
  838. mText.setTextColor(Color.RED);
  839.  
  840. }
  841.  
  842. else if(ColorList[item].equals("Green")){
  843. mText.setTextColor(Color.GREEN);
  844.  
  845. }
  846.  
  847. else if(ColorList[item].equals("Blue")){
  848. mText.setTextColor(Color.BLUE);
  849.  
  850. }
  851.  
  852. else if(ColorList[item].equals("Orange")){
  853. mText.setTextColor(Color.MAGENTA);
  854.  
  855. }
  856.  
  857. else if(ColorList[item].equals("White")){
  858. mText.setTextColor(Color.WHITE);
  859.  
  860. }
  861.  
  862. else if(ColorList[item].equals("Gray")){
  863. mText.setTextColor(Color.GRAY);
  864.  
  865. }
  866.  
  867. else if(ColorList[item].equals("Black")){
  868. mText.setTextColor(Color.BLACK);
  869.  
  870. }
  871.  
  872. else if(ColorList[item].equals("Yellow")){
  873. mText.setTextColor(Color.YELLOW);
  874.  
  875. }
  876.  
  877.  
  878. alert1.dismiss();
  879.  
  880.  
  881. }
  882. });
  883.  
  884. alt_bld1.setNegativeButton("Cancel",
  885. new DialogInterface.OnClickListener() {
  886. @Override
  887. public void onClick(DialogInterface dialog, int which) {
  888.  
  889. }
  890. });
  891.  
  892. alert1 = alt_bld1.create();
  893. alert1.show();
  894. }
  895. });
  896.  
  897. alt_bld.setNegativeButton("Cancel",
  898. new DialogInterface.OnClickListener() {
  899. @Override
  900. public void onClick(DialogInterface dialog, int which) {
  901.  
  902. }
  903. });
  904.  
  905. alert = alt_bld.create();
  906. alert.show();
  907. }
  908. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement