導航:首頁 > 源碼編譯 > gif信息c源碼

gif信息c源碼

發布時間:2023-04-13 06:14:35

1. 怎麼用C語言讀取gif圖片內容文件

分類: 電腦/網路 >> 程序設計 >> 其他編程語言
問題描述:

怎麼用C語言讀取賀拆備gif圖片內容文件 假如文件中有6個gif圖片,只讀取第一個圖片;讀完後寫入一個空文件中

解析:

用二進制文件方法打開。

(1)讀gif_id,輸出gif_id, 6 bytes

(2)讀logical_screen_descriptor(結構),並輸出

(3)如果 ScrHd.flag_GC_table == 1,

則有全局色表,則讀全局色表,並輸出

(4)循環,

檢查gif塊的類御賣型,按塊的類型讀塊,並輸出

若:

case: 0x2c -- 它是,Image Descriptor(結構),讀塊並輸出

判斷有無色表,有則讀塊並輸出,

下面 1 byte 表示 lZW min Code Size,讀並輸出

子塊 (include size, bytes*size data) 讀塊並輸出

子塊 (include size, bytes*size data) 讀塊並輸出

可能有很多子塊,讀塊並輸出

直到 0x00 讀塊並輸出,

break;

若case: 0x21 0xf9 -- 控制塊,讀到 0x00, 並輸出

break;

若case: 0x21 0xFe -- 註解塊,讀到 0x00,並輸出

break;

若case: 0x21 0x01 -- 普通禪毀文本塊,讀到 0x00,並輸出

break;

若case: 0x21 0xff -- 應用程序塊,讀到 0x00,並輸出

break;

若case: 0x3B -- END 第一個圖片完畢的標識,並輸出

break;

default: 列印「文件錯誤」break;

(5)關閉文件。

2. 請教:怎麼樣能把C語言代碼運行後的流星雨效果圖保存下來,保存為GIF。

搞定。 我用悔肆的拍前坦C++Builder XE2編譯器。 增中代碼: #include <vcl.h> #include <GIFimg.hpp> TGIFImage *image; 在wmain函數後部分: image = new TGIFImage(); srand((int) GetCurrentTime()); // 初始化隨機數發生器 image->Width = Screen->Width; image->Height = Screen->Height; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } ShowCursor(TRUE); // 顯示滑鼠游標 image->SaveToFile("流星雨襲桐.gif"); delete image; 在WndProc函數處理WM_TIMER消息後面增加: BitBlt(hdc, 0, 0, cxScreen, cyScreen, hdcMem, 0, 0, SRCCOPY); { Graphics::TBitmap *bmp = new Graphics::TBitmap; bmp->Width=Screen->Width; bmp->Height=Screen->Height; BitBlt(HDC(bmp->Canvas->Handle), 0, 0, cxScreen, cyScreen, hdcMem, 0, 0, SRCCOPY); image->Add(bmp); delete bmp; } ReleaseDC(hwnd, hdc); 編譯後成功。 保存的GIF文件很大,最好用Ulead GIF Animator優化一下。 需要編譯後的文件QQ我:1848447992

記得採納啊

3. 求GIF格式圖片解析顯示的C語言源碼

// File name : l2_gl_gif.h
#ifndef _GIF_H
#define _GIF_H

#define COMPRESSED_BUFFER_SIZE (25*1024) // maximal size of single compressed image data
#define GIF_DEFAULT_BKCOLOR (0xffff)
#define CODE_UPPER_BOUND 4096 // decided by algorithem itselt, maximal size of string table

typedef unsigned short COLORREF;

typedef struct tagCodeTableItem
{
unsigned short ushPrevIndex; // Previous code index
unsigned char uchCharacter; // character added this time
unsigned char uchFirstChar; // first character of the string this code corresponding to
unsigned char* pUchStringAddr; //
unsigned short ushStringLength;
} CODE_TABLE;

typedef struct tagImageInfoParameter
{
unsigned short ushImageLeftPosition;
unsigned short ushImageTopPosition;
unsigned short ushImageWidth;
unsigned short ushImageHeight;
unsigned short ushDelay;
bool blLocalColorTableFlag;// whether this image use private color table
unsigned short ushSizeofLocalColorTable;
bool blTransparentColorFlag;// whether this image use transparent index data
unsigned char uchTransparentColorIndex;
bool blInterlaceFlag; // whether this image is interlaced
bool blSortFlag; // not so important for our LCD device
unsigned short ushReserved;
} IMAGE_INFO_PARAMETER; //used as function parameter which could provided more information than usually used para

#define MAX_IMAGE_COUNT 20 // can process as many as MAX_IMAGE_COUNT sub-image of a gif file
//if it contains more than MAX_IMAGE_COUNT subimages

typedef struct tagImageRawInfo // used to keep raw subimage information
{
bool blGraphicControlExtension;
unsigned char uchGCE[8];
bool blImageDescriptor;
unsigned char uchImgDesp[12];
const unsigned char*pUchCodedImageData;
const unsigned char*pUchLocalColorTable;
} IMAGE_RAW_INFO;

typedef struct gif_context
{
IMAGE_RAW_INFO g_ImageRawInfo[MAX_IMAGE_COUNT];
CODE_TABLE g_CodeTable[CODE_UPPER_BOUND];
unsigned char g_uchLZWCodeSize; // 初始的壓縮code size
unsigned char g_uchOffset; // 取code時基於位的偏移
const unsigned char*g_pUchCompressedData; // 指向壓縮數據的首指針
unsigned char* g_pImageIndexData; // 指向解壓縮後數據的首指針
unsigned char* g_pUchImageIndexPos;
unsigned short gifThisWidth;
unsigned short gifThisHeight;
unsigned short g_ushImageCount;
COLORREF g_bkColor;
////////////////2004/06/22
unsigned char DisposalMethod;
gdc_t *FirstFrameSd;// 當Disposal Method 為1,
//且存在尺度變換,需要保留第一幀數據備用
unsigned long length; // add for techfaith porting,08/01/2007
} GIF_CONTEXT, LPGIF_CONTEXT;

bool _GetGifFileInfor(GIF_CONTEXT* pGif_Context,const unsigned char* pGifFileStream);
bool pt_gif_draw_one_frame(gdc_t* sd, short x, short y,
const unsigned char* pGifData,int iFrameNum);

/************************************************************
*
* gif playing using task, currently support up to
* MAX_CONCURRENCE_NUMBER gif playing concurrently
*
*************************************************************/

//#define MAX_CONCURRENCE_NUMBER 8
//#define PV_GIF_PLAYING_INTERVER 1000
//#define GIFPLAY_FREE 0
//#define GIFPLAY_BUSY 1

typedef struct
{
GIF_CONTEXT gif_Context;
COLORREF Palette[384];
//unsigned long taskEntry;
//void* Form;
unsigned short playIndex;
unsigned short frameNumber;
unsigned short playTimes;
//unsigned char timerNo;
const unsigned char*pGifFileStream;
unsigned char* pDecodedBuf;
unsigned short width, height;
short x, y;
bool UseShrink;
unsigned short DispWidth, DispHeight;
gdc_t *gdc;
} gif_handle_t,*GIFPLAY_HANDLE;

#endif // _GIF_H

4. 用vc如何播放gif

使用MMAPI播放辯檔宏gif動畫MMAPI是在JSR 135中提出的,增強了java ME平台對多媒體編程的支持。例如播放音頻和視頻文件,捕獲聲音和圖像等。目前大多數支持JTWI 1.0的手機都支持了MMAPI。本文介紹如何使用MMAPI播放gif格式的動畫。

其實製作動畫效果可以有很多辦法,例如准備一個圖片數組,在程序中不斷的切換顯示不同的圖片,只要時間的間隔設置合理即可出現動畫的效果。攜冊如果使用MMAPI則可以直接播放gif的動畫。其實這蠢叢和播放視頻文件的方法和流程是類似的。

首先我們應該准備一個gif文件,放在能夠訪問到的位置,且確保這個文件會被打包進jar內。在創建播放器之前應該先確認手機上的MMAPI實現是否支持image/gif格式的播放,如果支持則創建Player,如下。

private void createPlayer(InputStream is){
String[] contents = Manager.getSupportedContentTypes(null);
for(int i = 0;i<contents.length;i++){
if(contents[i].toLowerCase().indexOf("image/gif") != -1){
try {
player = Manager.createPlayer(is,"image/gif");
player.realize();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}

}

}
}

Player創建後,我們需要獲得VideoControl,然後將內容渲染到屏幕上,VideoControl提供了兩種模式,這里我們使用USE_GUI_PRIMITIVE方式,將返回的Item追加到一個Form中顯示。最後調用Player.start()即可播放。注意在退出之前一定要釋放Player資源,關閉Player並設置為null。GifPlayer的源碼如下:

源程序如下

/*
* GifPlayer.java
*
* Created on 2006年6月21日, 下午7:28
*/

package com.j2medev.gif;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lci.Display;
import javax.microedition.lci.Form;
import javax.microedition.lci.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.*;

/**
*
* @author ming
* @version
*/
public class GifPlayer extends MIDlet {

private Display display = null;
private Player player = null;

public void startApp() {
if(display == null)
display = Display.getDisplay(this);
Form form = new Form("gif player");
InputStream is = getClass().getResourceAsStream("/a.gif");
createPlayer(is);
if(player == null){
form.append("can not play image/gif");
}else{
VideoControl vc = (VideoControl)player.getControl("VideoControl");
if(vc != null){
form.append((Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null));
}
}
display.setCurrent(form);
try {
player.start();
} catch (MediaException ex) {
ex.printStackTrace();
}
}

private void createPlayer(InputStream is){
String[] contents = Manager.getSupportedContentTypes(null);
for(int i = 0;i<contents.length;i++){
if(contents[i].toLowerCase().indexOf("image/gif") != -1){
try {
player = Manager.createPlayer(is,"image/gif");
player.realize();
} catch (IOException ex) {
ex.printStackTrace();
} catch (MediaException ex) {
ex.printStackTrace();
}

}

}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
if(player != null){
player.close();
player = null;

5. 如何用c#讀取gif和jpg的圖象象素信息

給你一段襲橡我編的代碼,功賣簡能是變圖片的解析度,一看拍配旁就明白了
Color c = new Color();
Bitmap box1 = new Bitmap(pictureBox1.Image);
Bitmap box2 = new Bitmap(pictureBox2.Image);
int r, g, b, i, j, size, k1, k2, xres, yres;
xres = pictureBox1.Image.Width;
yres = pictureBox1.Image.Height;
size = 2;
for (i = 0; i < (xres - 1);i+=size)
{
for (j = 0; j <( yres - 1); j += size)
{
c = box1.GetPixel(i,j);//取像素點
r = c.R;
g = c.G;
b = c.B;

Color cc = Color.FromArgb(r,g,b);
for (k1 = 0; k1 <= (size - 1);k1++)
{
for (k2 = 0; k2 <= (size - 1); k2++)
{
box2.SetPixel(i+k1,j+k2,cc);//寫入像素
}
}

}
}

6. 有人知道如何用C/C++/C#將.GIF格式的圖片讀取並且顯示出來

c#picture可以直接顯示gif

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace WindowsApplication1
{
/// <summary>
/// Form8 的摘要說明。
/// </summary>
public class animateImage : System.Windows.Forms.Form
{
/// <summary>
/// 必需的設計器變數。
/// </summary>
private System.ComponentModel.Container components = null;
Bitmap animatedImage = new Bitmap("1.gif");
bool currentlyAnimating = false;
public animateImage()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();

//
// TODO: 在中差斗 InitializeComponent 調用後添加任何構造函數代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯賣磨器慶差修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
//
// Form8
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 438);
this.Name = "Form8";
this.Text = "Form8";
this.Load += new System.EventHandler(this.Form8_Load);

}
#endregion
// [STAThread]
// static void Main()
// {
// Application.Run(new Form2());
// }

private void Form8_Load(object sender, System.EventArgs e)
{

//This method begins the animation.

}
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
currentlyAnimating = true;

}
}
private void OnFrameChanged(object o, EventArgs e)
{
//Force a call to the Paint event handler.
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.DoubleBuffer,true);
//Begin the animation.
AnimateImage();
//Get the next frame ready for rendering.
ImageAnimator.UpdateFrames();
//Draw the next frame in the animation.
e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
e.Graphics.DrawString("哈哈",new Font("Tahoma",12),new SolidBrush(Color.Red),10,10);
}
// public static void Main()
// {
// Application.Run(new animateImage());
// }

}
}

7. 怎麼將gif格式的圖片轉換為c語言程序

圖片是不能轉換成C程序的,只有通過調用,才能實現圖片的模橘輸出。例如,我們常見的網游,就是通過一系列的調用其旦舉團本身已有的圖片或動畫來實現的,所以做網游的公司里,學美術的人是必不可少的。
具體方法答燃看書吧,書上都有詳細的解答的。

8. 急求,linux下用c語言實現顯示gif圖像(靜態即可),虛擬機Ubuntu環境,求代碼。。。。

eog, 右啟棗鋒悄晌岩宏側有c源碼下載.
http://projects.gnome.org/eog/

閱讀全文

與gif信息c源碼相關的資料

熱點內容
什麼是編譯器指令 瀏覽:219
微控制器邏輯命令使用什麼匯流排 瀏覽:885
程序員在學校里是學什麼的 瀏覽:601
oraclejava數據類型 瀏覽:890
程序員考注冊會計師 瀏覽:957
怎麼使用access的命令按鈕 瀏覽:899
有點錢app在哪裡下載 瀏覽:832
博途v15解壓後無法安裝 瀏覽:205
什麼是根伺服器主機 瀏覽:438
安卓手游怎麼申請退款 瀏覽:555
安卓系統如何分享網頁 瀏覽:278
ad如何編譯pcb工程 瀏覽:414
除了滴滴app哪裡還能用滴滴 瀏覽:399
截圖怎麼保存文件夾然後壓縮 瀏覽:8
幻影伺服器怎麼樣 瀏覽:27
具體哪些廣東公司招程序員 瀏覽:870
嵌入式編譯器教程 瀏覽:306
ssl數據加密傳輸 瀏覽:86
51單片機定時器方式2 瀏覽:332
命令行查看開機時間 瀏覽:813